Export (0) Print
Expand All

DataColumn.ReadOnly Property

Gets or sets a value indicating whether the column allows changes once a row has been added to the table.

[Visual Basic]
Public Property ReadOnly As Boolean
[C#]
public bool ReadOnly {get; set;}
[C++]
public: __property bool get_ReadOnly();
public: __property void set_ReadOnly(bool);
[JScript]
public function get ReadOnly() : Boolean;
public function set ReadOnly(Boolean);

Property Value

true if the column is read only; otherwise, false. The default is false.

Exceptions

Exception Type Condition
ArgumentException The property is set to false on a computed column.

Example

[Visual Basic, C#, C++] The following example creates a DataColumn and sets its ReadOnly property true.

[Visual Basic] 
Private Sub AddColumn(ByVal myTable As DataTable)
    ' Add a DataColumn to the collection and set its properties.
    Dim myColumn As DataColumn
    ' The constructor sets the ColumnName of the column.
    myColumn = myTable.Columns.Add("Total")
    myColumn.DataType = System.Type.GetType("System.Decimal")
    myColumn.ReadOnly = True
    myColumn.Expression = "UnitPrice * Quantity"
    myColumn.Unique = False
 End Sub

[C#] 
private void AddColumn(DataTable myTable){
    // Add a DataColumn to the collection and set its properties.
    DataColumn myColumn;
    // The constructor sets the ColumnName of the column.
    myColumn = myTable.Columns.Add("Total");
    myColumn.DataType = System.Type.GetType("System.Decimal");
    myColumn.ReadOnly = true;
    myColumn.Expression = "UnitPrice * Quantity";
    myColumn.Unique = false;
 }

[C++] 
private:
void AddColumn(DataTable* myTable){
    // Add a DataColumn to the collection and set its properties.
    DataColumn* myColumn;
    // The constructor sets the ColumnName of the column.
    myColumn = myTable->Columns->Add(S"Total");
    myColumn->DataType = System::Type::GetType(S"System.Decimal");
    myColumn->ReadOnly = true;
    myColumn->Expression = S"UnitPrice * Quantity";
    myColumn->Unique = false;
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataColumn Class | DataColumn Members | System.Data Namespace | Unique | AutoIncrement

Show:
© 2014 Microsoft