DataGridTextBoxColumn Class
Hosts a TextBox control in a cell of a DataGridColumnStyle for editing strings.
For a list of all members of this type, see DataGridTextBoxColumn Members.
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.DataGridColumnStyle
System.Windows.Forms.DataGridTextBoxColumn
[Visual Basic] Public Class DataGridTextBoxColumn Inherits DataGridColumnStyle [C#] public class DataGridTextBoxColumn : DataGridColumnStyle [C++] public __gc class DataGridTextBoxColumn : public DataGridColumnStyle [JScript] public class DataGridTextBoxColumn extends DataGridColumnStyle
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
The DataGridTextBoxColumn class derives from the abstract (MustInherit in Visual Basic) class DataGridColumnStyle. At run time, the DataGridTextBoxColumn hosts a DataGridTextBox control that allows users to edit text.
Special properties added to the class include Format, and HideEditBox. These properties allow you to access the hosted DataGridTextBox control and its attributes, and set the format for displaying values.
If the data source is a DataTable containing DataColumn objects, the DataType property of the DataColumn should be set to a data type that can logically be edited in a text box control. The following data types are automatically associated with a DataGridTextBoxColumn: Byte, DateTime, Decimal, Double, Int16, Int32, Int64, UInt16, UInt32, UInt64, Single, and String.
[Visual Basic] Note The following types are not fully supported by Visual Basic: DateTime, UInt16, UInt32, UInt64, and TimeSpan. (Operators are not allowed.)
Example
[Visual Basic, C#, C++] The following example creates a DataGridTextBoxColumn is and adds it to the GridColumnStylesCollection. For this code example to run, you must provide the fully qualified assembly name. For information about how to obtain the fully qualified assembly name, see Assembly Names.
[Visual Basic] Private Sub AddColumn() Dim myTable As New DataTable() ' Add a new DataColumn to the DataTable. Dim myColumn As New DataColumn("myTextBoxColumn") myColumn.DataType = System.Type.GetType("System.String") myColumn.DefaultValue = "default string" myTable.Columns.Add(myColumn) ' Get the CurrencyManager for the DataTable. Dim cm As CurrencyManager = CType(Me.BindingContext(myTable), CurrencyManager) ' Use the CurrencyManager to get the PropertyDescriptor for the new column. Dim pd As PropertyDescriptor = cm.GetItemProperties()("myTextBoxColumn") Dim myColumnTextColumn As DataGridTextBoxColumn ' Create the DataGridTextBoxColumn with the PropertyDescriptor. myColumnTextColumn = New DataGridTextBoxColumn(pd) ' Add the new DataGridColumn to the GridColumnsCollection. dataGrid1.DataSource = myTable dataGrid1.TableStyles.Add(New DataGridTableStyle()) dataGrid1.TableStyles(0).GridColumnStyles.Add(myColumnTextColumn) End Sub 'AddColumn [C#] private void AddColumn() { DataTable myTable= new DataTable(); // Add a new DataColumn to the DataTable. DataColumn myColumn = new DataColumn("myTextBoxColumn"); myColumn.DataType = System.Type.GetType("System.String"); myColumn.DefaultValue="default string"; myTable.Columns.Add(myColumn); // Get the CurrencyManager for the DataTable. CurrencyManager cm = (CurrencyManager)this.BindingContext[myTable]; // Use the CurrencyManager to get the PropertyDescriptor for the new column. PropertyDescriptor pd = cm.GetItemProperties()["myTextBoxColumn"]; DataGridTextBoxColumn myColumnTextColumn; // Create the DataGridTextBoxColumn with the PropertyDescriptor. myColumnTextColumn = new DataGridTextBoxColumn(pd); // Add the new DataGridColumn to the GridColumnsCollection. dataGrid1.DataSource= myTable; dataGrid1.TableStyles.Add(new DataGridTableStyle()); dataGrid1.TableStyles[0].GridColumnStyles.Add(myColumnTextColumn); } [C++] private: void AddColumn() { DataTable __gc *myTable= new DataTable(); // Add a new DataColumn to the DataTable. DataColumn __gc *myColumn = new DataColumn(S"myTextBoxColumn"); myColumn->DataType = System::Type::GetType(S"System::String"); myColumn->DefaultValue = S"default string"; myTable->Columns->Add(myColumn); // Get the CurrencyManager for the DataTable. CurrencyManager __gc *cm = dynamic_cast<CurrencyManager *>(this->BindingContext->Item[myTable]); // Use the CurrencyManager to get the PropertyDescriptor for the new column. System::ComponentModel::PropertyDescriptor __gc *pd = cm->GetItemProperties()->Item[S"myTextBoxColumn"]; DataGridTextBoxColumn __gc *myColumnTextColumn; // Create the DataGridTextBoxColumn with the PropertyDescriptor. myColumnTextColumn = new DataGridTextBoxColumn(pd); // Add the new DataGridColumn to the GridColumnsCollection. dataGrid1->DataSource = myTable; dataGrid1->TableStyles->Add(new DataGridTableStyle()); dataGrid1->TableStyles->Item[0]->GridColumnStyles->Add(myColumnTextColumn); };
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Windows.Forms
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
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
See Also
DataGridTextBoxColumn Members | System.Windows.Forms Namespace | DataGridBoolColumn | DataGridColumnStyle | DataColumn | DataType | DataGrid | DataGridTextBox | TextBox