DataColumn.ReadOnly DataColumn.ReadOnly DataColumn.ReadOnly DataColumn.ReadOnly Property

定義

取得或設定值,指出是否資料列一加入至資料表,就允許變更資料行。Gets or sets a value that indicates whether the column allows for changes as soon as a row has been added to the table.

public:
 property bool ReadOnly { bool get(); void set(bool value); };
[System.Data.DataSysDescription("DataColumnReadOnlyDescr")]
public bool ReadOnly { get; set; }
member this.ReadOnly : bool with get, set
Public Property ReadOnly As Boolean

屬性值

如果資料行是唯讀,則為 true,否則為 falsetrue if the column is read only; otherwise, false. 預設為 falseThe default is false.

例外狀況

屬性在計算的資料行上設定為 falseThe property is set to false on a computed column.

範例

下列範例會建立DataColumn並設定其ReadOnly屬性trueThe following example creates a DataColumn and sets its ReadOnly property true.

private void AddColumn(DataTable table)
{
    // Add a DataColumn to the collection and set its properties.
    // The constructor sets the ColumnName of the column.
    DataColumn column = table.Columns.Add("Total");
    column.DataType = System.Type.GetType("System.Decimal");
    column.ReadOnly = true;
    column.Expression = "UnitPrice * Quantity";
    column.Unique = false;
}
Private Sub AddColumn(ByVal table As DataTable)
    ' Add a DataColumn to the collection and set its properties.
    ' The constructor sets the ColumnName of the column.
    Dim column As DataColumn = table.Columns.Add("Total")
    column.DataType = System.Type.GetType("System.Decimal")
    column.ReadOnly = True
    column.Expression = "UnitPrice * Quantity"
    column.Unique = False
End Sub

適用於

另請參閱