DataGridTextBoxColumn 类    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在 TextBox 的单元格中承载 DataGridColumnStyle 控件以便编辑字符串。
public ref class DataGridTextBoxColumn : System::Windows::Forms::DataGridColumnStylepublic class DataGridTextBoxColumn : System.Windows.Forms.DataGridColumnStyletype DataGridTextBoxColumn = class
    inherit DataGridColumnStylePublic Class DataGridTextBoxColumn
Inherits DataGridColumnStyle- 继承
示例
以下示例创建 ,DataGridTextBoxColumn并将其添加到 的 。GridColumnStylesCollectionDataGrid 若要运行此代码示例,请将其粘贴到具有 DataGrid 命名 dataGrid1 的窗体中,并从 的 Form构造函数调用它。
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.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 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
注解
类 DataGridTextBoxColumn 派生自 abstract 类 DataGridColumnStyle。 在运行时, 承载 DataGridTextBoxColumn 一个 DataGridTextBox 允许用户编辑文本的控件。
添加到 类的特殊属性包括 Format、 和 HideEditBox。 这些属性允许访问托管 DataGridTextBox 控件及其属性,并设置显示值的格式。
如果数据源是包含DataTableDataColumn的对象,DataType应将 的 DataColumn 属性设置为可在文本框控件中以逻辑方式编辑的数据类型。 以下数据类型自动与 DataGridTextBoxColumn :Byte、、DateTime、Decimal、DoubleInt16、Int32、、Int64、UInt16、UInt64UInt32Single、 和 String关联。
构造函数
| DataGridTextBoxColumn() | 初始化 DataGridTextBoxColumn 类的新实例。 | 
| DataGridTextBoxColumn(PropertyDescriptor) | 使用指定的 PropertyDescriptor初始化 类的新实例DataGridTextBoxColumn。 | 
| DataGridTextBoxColumn(PropertyDescriptor, Boolean) | 使用指定的 DataGridTextBoxColumn 初始化 PropertyDescriptor 类的新实例。 指定 DataGridTextBoxColumn 是否为默认列。 | 
| DataGridTextBoxColumn(PropertyDescriptor, String) | 使用指定的 PropertyDescriptor 和 格式初始化 类的新实例DataGridTextBoxColumn。 | 
| DataGridTextBoxColumn(PropertyDescriptor, String, Boolean) | 使用指定的 DataGridTextBoxColumn 和格式初始化 PropertyDescriptor 类的新实例。 指定此列是否为默认列。 | 
属性
| Alignment | 获取或设置列中文本的对齐方式。(继承自 DataGridColumnStyle) | 
| CanRaiseEvents | 获取一个指示组件是否可以引发事件的值。(继承自 Component) | 
| Container | 获取包含 IContainer 的 Component。(继承自 Component) | 
| DataGridTableStyle | 获取列的 DataGridTableStyle。(继承自 DataGridColumnStyle) | 
| DesignMode | 获取一个值,用以指示 Component 当前是否处于设计模式。(继承自 Component) | 
| Events | 获取附加到此 Component 的事件处理程序的列表。(继承自 Component) | 
| FontHeight | 获取该列字体的高度。(继承自 DataGridColumnStyle) | 
| Format | 获取或设置指定格式化文本的方法的一个或多个字符。 | 
| FormatInfo | 获取或设置用于确定格式化值的方法的特定区域性信息。 | 
| HeaderAccessibleObject | 获取列的 AccessibleObject。(继承自 DataGridColumnStyle) | 
| HeaderText | 获取或设置列标题的文本。(继承自 DataGridColumnStyle) | 
| MappingName | 获取或设置列样式所映射到的数据成员的名称。(继承自 DataGridColumnStyle) | 
| NullText | 获取或设置在列包含  | 
| PropertyDescriptor | 获取或设置 PropertyDescriptor 的 DataGridTextBoxColumn。 | 
| ReadOnly | 设置一个值,该值指示文本框列是否为只读。 | 
| Site | (继承自 Component) | 
| TextBox | 获取寄宿的 TextBox 控件。 | 
| Width | 获取或设置列的宽度。(继承自 DataGridColumnStyle) | 
方法
事件
| AlignmentChanged | 在 Alignment 属性值更改时发生。(继承自 DataGridColumnStyle) | 
| Disposed | 在通过调用 Dispose() 方法释放组件时发生。(继承自 Component) | 
| FontChanged | 当列的字体更改时发生。(继承自 DataGridColumnStyle) | 
| HeaderTextChanged | 在 HeaderText 属性值更改时发生。(继承自 DataGridColumnStyle) | 
| MappingNameChanged | 当 MappingName 值更改时发生。(继承自 DataGridColumnStyle) | 
| NullTextChanged | 当 NullText 值更改时发生。(继承自 DataGridColumnStyle) | 
| PropertyDescriptorChanged | 在 PropertyDescriptor 属性值更改时发生。(继承自 DataGridColumnStyle) | 
| ReadOnlyChanged | 在 ReadOnly 属性值更改时发生。(继承自 DataGridColumnStyle) | 
| WidthChanged | 在 Width 属性值更改时发生。(继承自 DataGridColumnStyle) | 
显式接口实现
| IDataGridColumnStyleEditingNotificationService.ColumnStartedEditing(Control) | 通知 DataGrid 控件用户已开始编辑该列。(继承自 DataGridColumnStyle) |