共用方式為


DataGridViewRow.ReadOnly 屬性

定義

取得或設定一個值,表示該列是否為唯讀。

public:
 virtual property bool ReadOnly { bool get(); void set(bool value); };
[System.ComponentModel.Browsable(true)]
public override bool ReadOnly { get; set; }
[<System.ComponentModel.Browsable(true)>]
member this.ReadOnly : bool with get, set
Public Overrides Property ReadOnly As Boolean

屬性值

true若該列為唯讀;否則,。 false

屬性

例外狀況

該列屬於 DataGridView 控制區,且是共用列。

範例

以下程式碼範例示範如何使用該 DataGridViewBand.ReadOnly 性質,該性質幾乎與 ReadOnly 類別的 DataGridViewRow 性質相同。 此程式碼範例是本類別更大範例 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 該列中每個儲存格的性質。

若屬性 DataGridView.ReadOnly 值為 true,設定此屬性無效。

適用於

另請參閱