DataGridViewColumn.ReadOnly 屬性

定義

取得或設定值,指出使用者是否可以編輯資料行的儲存格。

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

屬性值

Boolean

如果使用者不能編輯資料行的儲存格,則為 true,否則為 false

例外狀況

這個屬性是為繫結至唯讀資料來源的資料行設定為 false

範例

下列程式碼範例示範如何使用 DataGridViewBand.ReadOnly 屬性,這與 類別的 DataGridViewColumn 屬性幾乎相同 ReadOnly 。 此程式碼範例是類別概觀所提供較大範例的 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 資料行中每個儲存格的屬性。

適用於

另請參閱