DataGridTextBoxColumn 类

DataGridColumnStyle 的单元格中承载 TextBox 控件以便编辑字符串。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Class DataGridTextBoxColumn
    Inherits DataGridColumnStyle
用法
Dim instance As DataGridTextBoxColumn
public class DataGridTextBoxColumn : DataGridColumnStyle
public ref class DataGridTextBoxColumn : public DataGridColumnStyle
public class DataGridTextBoxColumn extends DataGridColumnStyle
public class DataGridTextBoxColumn extends DataGridColumnStyle

备注

DataGridTextBoxColumn 类从 abstractDataGridColumnStyle 派生。在运行时,DataGridTextBoxColumn 承载允许用户编辑文本的 DataGridTextBox 控件。

添加到该类的特殊属性包括 FormatHideEditBox。这些属性使您可以访问寄宿的 DataGridTextBox 控件及其属性,并设置显示值的格式。

如果数据源是包含 DataColumn 对象的 DataTable,那么 DataColumnDataType 属性应设置为一个可以在文本框控件中进行逻辑编辑的数据类型。下列数据类型自动与 DataGridTextBoxColumnByteDateTimeDecimalDoubleInt16Int32Int64UInt16UInt32UInt64SingleString 关联。

提示

Visual Basic 不完全支持以下类型:DateTimeUInt16UInt32UInt64TimeSpan。(不允许使用运算符。)

示例

下面的示例创建一个 DataGridTextBoxColumn,并将其添加到 GridColumnStylesCollection 中。要运行该代码实例,必须提供完全限定程序集名称。有关如何获取完全限定程序集名称的信息,请参见 程序集名称

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
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);
 }
private:
   void AddColumn()
   {
      DataTable^ myTable = gcnew DataTable;
      
      // Add a new DataColumn to the DataTable.
      DataColumn^ myColumn = gcnew 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 = dynamic_cast<CurrencyManager^>(this->BindingContext[ myTable ]);
      
      // Use the CurrencyManager to get the PropertyDescriptor for the new column.
      System::ComponentModel::PropertyDescriptor^ pd = cm->GetItemProperties()[ "myTextBoxColumn" ];
      DataGridTextBoxColumn^ myColumnTextColumn;
      
      // Create the DataGridTextBoxColumn with the PropertyDescriptor.
      myColumnTextColumn = gcnew DataGridTextBoxColumn( pd );
      
      // Add the new DataGridColumn to the GridColumnsCollection.
      dataGrid1->DataSource = myTable;
      dataGrid1->TableStyles->Add( gcnew DataGridTableStyle );
      dataGrid1->TableStyles[ 0 ]->GridColumnStyles->Add( myColumnTextColumn );
   }
private void AddColumn()
{
    DataTable myTable = new DataTable();
    // Add a new DataColumn to the DataTable.
    DataColumn myColumn = new DataColumn("myTextBoxColumn");
    myColumn.set_DataType(System.Type.GetType("System.String"));
    myColumn.set_DefaultValue("default string");
    myTable.get_Columns().Add(myColumn);
    // Get the CurrencyManager for the DataTable.
    CurrencyManager cm = (CurrencyManager)(this.get_BindingContext().
        get_Item(myTable));
    // Use the CurrencyManager to get the PropertyDescriptor 
    // for the new column.
    PropertyDescriptor pd = cm.GetItemProperties().
        get_Item("myTextBoxColumn");
    DataGridTextBoxColumn myColumnTextColumn;

    // Create the DataGridTextBoxColumn with the PropertyDescriptor.
    myColumnTextColumn = new DataGridTextBoxColumn(pd);

    // Add the new DataGridColumn to the GridColumnsCollection.
    dataGrid1.set_DataSource(myTable);
    dataGrid1.get_TableStyles().Add(new DataGridTableStyle());
    dataGrid1.get_TableStyles().get_Item(0).
        get_GridColumnStyles().Add(myColumnTextColumn);
} //AddColumn

继承层次结构

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.DataGridColumnStyle
        System.Windows.Forms.DataGridTextBoxColumn

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

DataGridTextBoxColumn 成员
System.Windows.Forms 命名空间
DataGridBoolColumn 类
DataGridColumnStyle 类
DataColumn
DataType
DataGrid 类
DataGridTextBox 类
TextBox