DataGridViewBand.ReadOnly 屬性

定義

取得或設定值,指出使用者是否可以編輯群組列的儲存格。

public:
 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,否則為 false。 預設為 false

例外狀況

當設定這個屬性時,這個 DataGridViewBand 執行個體會是共用的 DataGridViewRow

範例

下列程式碼範例示範如何使用 ReadOnly 屬性來停用整個 DataGridView 的編輯。 此程式碼範例是提供給 類別之較大範例的 DataGridViewBand 一部分。

// 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
    Next
End Sub

備註

屬性 ReadOnly 會影響 DataGridViewCell.ReadOnly 帶狀區中每個儲存格的 屬性。 例如,如果 ReadOnlyDataGridViewRow 屬性變更,則 DataGridViewCell.ReadOnly 資料列中所有儲存格的 屬性都會變更。

適用於

另請參閱