DataGridColumnStyle.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

属性值

Boolean

如果数据不能编辑,则为 true;否则为 false

示例

下面的代码示例将DataGridColumnStyle对象的ReadOnly属性设置为与对象的ReadOnly属性相同的值DataColumn

void SetReadOnly()
{
   DataColumnCollection^ myDataColumns;
   
   // Get the columns for a table bound to a DataGrid.
   myDataColumns = dataSet1->Tables[ "Suppliers" ]->Columns;
   System::Collections::IEnumerator^ myEnum = myDataColumns->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      DataColumn^ dataColumn = safe_cast<DataColumn^>(myEnum->Current);
      dataGrid1->TableStyles[ 0 ]->GridColumnStyles[ dataColumn->ColumnName ]->ReadOnly = dataColumn->ReadOnly;
   }
}
private void SetReadOnly()
{
    DataColumnCollection myDataColumns;
    // Get the columns for a table bound to a DataGrid.
    myDataColumns = dataSet1.Tables["Suppliers"].Columns;
    foreach(DataColumn dataColumn in myDataColumns)
    {
        dataGrid1.TableStyles[0].GridColumnStyles[dataColumn.ColumnName].ReadOnly = dataColumn.ReadOnly;
    }
}
Private Sub SetReadOnly()
    Dim myColumn As DataGridColumnStyle
    Dim myDataColumns As DataColumnCollection
    ' Get the columns for a table bound to a DataGrid.
    myDataColumns = dataSet1.Tables("Suppliers").Columns
    Dim dataColumn As DataColumn
    For Each dataColumn In myDataColumns
        dataGrid1.TableStyles(0).GridColumnStyles(dataColumn.ColumnName).ReadOnly = dataColumn.ReadOnly
    Next dataColumn
End Sub

注解

如果列包含主键,或者其值在设置为) 时 DataColumn AutoIncrement true 自动生成 (,则为只读列。

其他类上也存在类似的只读属性,每个类都允许对数据的访问进行更多控制。 例如,System.Windows.Forms.DataGrid控件可以使用其ReadOnly属性设置为只读模式;DataGridTableStyle该控件还具有一个ReadOnlyReadOnly属性,并且该DataColumn类具有用于限制数据更新的属性。

适用于

另请参阅