DataGridViewBand.ReadOnly 属性


获取或设置一个值,该值指示用户是否可以编辑带区的单元格。Gets or sets a value indicating whether the user can edit the band's cells.

 virtual property bool ReadOnly { bool get(); void set(bool value); };
public virtual bool ReadOnly { get; set; }
member this.ReadOnly : bool with get, set
Public Overridable Property ReadOnly As Boolean


如果用户不能编辑带区的单元格,则为 true,否则为 falsetrue if the user cannot edit the band's cells; otherwise, false. 默认值为 falseThe default is false.


设置此属性时,此 DataGridViewBand 实例为共享的 DataGridViewRowWhen setting this property, this DataGridViewBand instance is a shared DataGridViewRow.


下面的代码示例演示如何使用ReadOnly属性禁用整个DataGridView的编辑。The following code example demonstrates how to use the ReadOnly property to disable editing for an entire DataGridView. 此代码示例是为DataGridViewBand类提供的更大示例的一部分。This code example is part of a larger example provided for the DataGridViewBand class.

// Make the entire DataGridView read only.
void Button8_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   System::Collections::IEnumerator^ myEnum = dataGridView->Columns->GetEnumerator();
   while ( myEnum->MoveNext() )
      DataGridViewBand^ band = safe_cast<DataGridViewBand^>(myEnum->Current);
      band->ReadOnly = true;

// Make the entire DataGridView read only.
private void Button8_Click(object sender, System.EventArgs e)
    foreach (DataGridViewBand band in dataGridView.Columns)
        band.ReadOnly = true;
' Make the entire DataGridView read only.
Private Sub Button8_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Button8.Click

    For Each band As DataGridViewBand In dataGridView.Columns
        band.ReadOnly = True
End Sub


属性影响带区DataGridViewCell.ReadOnly中每个单元的属性。 ReadOnlyThe ReadOnly property affects the DataGridViewCell.ReadOnly property of each cell in the band. 例如, 如果ReadOnly DataGridViewRow更改了的属性, 则该行中所有DataGridViewCell.ReadOnly单元格的属性将更改。For example, if the ReadOnly property of a DataGridViewRow changes, then the DataGridViewCell.ReadOnly property of all cells in the row will change.