DataGridTextBoxColumn 构造函数

定义

初始化 DataGridTextBoxColumn 类的新实例。Initializes a new instance of the DataGridTextBoxColumn class.

重载

DataGridTextBoxColumn()

初始化 DataGridTextBoxColumn 类的新实例。Initializes a new instance of the DataGridTextBoxColumn class.

DataGridTextBoxColumn(PropertyDescriptor)

使用指定的 DataGridTextBoxColumn 初始化 PropertyDescriptor 的一个新实例。Initializes a new instance of a DataGridTextBoxColumn with a specified PropertyDescriptor.

DataGridTextBoxColumn(PropertyDescriptor, Boolean)

使用指定的 DataGridTextBoxColumn 初始化 PropertyDescriptor 类的新实例。Initializes a new instance of the DataGridTextBoxColumn class using the specified PropertyDescriptor. 指定 DataGridTextBoxColumn 是否为默认列。Specifies whether the DataGridTextBoxColumn is a default column.

DataGridTextBoxColumn(PropertyDescriptor, String)

使用指定的 DataGridTextBoxColumn 和格式初始化 PropertyDescriptor 的一个新实例。Initializes a new instance of a DataGridTextBoxColumn with the specified PropertyDescriptor and format.

DataGridTextBoxColumn(PropertyDescriptor, String, Boolean)

使用指定的 DataGridTextBoxColumn 和格式初始化 PropertyDescriptor 类的新实例。Initializes a new instance of the DataGridTextBoxColumn class with a specified PropertyDescriptor and format. 指定此列是否为默认列。Specifies whether the column is the default column.

DataGridTextBoxColumn()

初始化 DataGridTextBoxColumn 类的新实例。Initializes a new instance of the DataGridTextBoxColumn class.

public:
 DataGridTextBoxColumn();
public DataGridTextBoxColumn ();
Public Sub New ()

示例

下面的示例创建一个 DataGridTextBoxColumn 并将其添加到 GridColumnStylesCollection 集合中。The following example creates a DataGridTextBoxColumn and adds it to the GridColumnStylesCollection collection.

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(PropertyDescriptor)

使用指定的 DataGridTextBoxColumn 初始化 PropertyDescriptor 的一个新实例。Initializes a new instance of a DataGridTextBoxColumn with a specified PropertyDescriptor.

public:
 DataGridTextBoxColumn(System::ComponentModel::PropertyDescriptor ^ prop);
public DataGridTextBoxColumn (System.ComponentModel.PropertyDescriptor prop);
new System.Windows.Forms.DataGridTextBoxColumn : System.ComponentModel.PropertyDescriptor -> System.Windows.Forms.DataGridTextBoxColumn
Public Sub New (prop As PropertyDescriptor)

参数

prop
PropertyDescriptor

PropertyDescriptor 将关联的列的 DataGridTextBoxColumnThe PropertyDescriptor for the column with which the DataGridTextBoxColumn will be associated.

示例

下面的示例创建一个 DataGridTextBoxColumn 并将其添加到 GridColumnStylesCollection 集合中。The following example creates a DataGridTextBoxColumn and adds it to the GridColumnStylesCollection collection.

private:
   void AddColumn( DataTable^ myTable )
   {
      // Add a new DataColumn to the DataTable.
      DataColumn^ myColumn = gcnew DataColumn( "myTextBoxColumn" );
      myColumn->DataType = String::typeid;
      myColumn->DefaultValue = "default string";
      myTable->Columns->Add( myColumn );

      // Get the ListManager for the DataTable.
      CurrencyManager^ cm = dynamic_cast<CurrencyManager^>(this->BindingContext[ myTable ]);

      // Use the ListManager to get the PropertyDescriptor for the new column.
      PropertyDescriptor^ pd = cm->GetItemProperties()[ "myTextBoxColumn" ];

      // Create a new DataTimeFormat object.
      DateTimeFormatInfo^ fmt = gcnew DateTimeFormatInfo;

      // Insert code to set format.
      DataGridTextBoxColumn^ myColumnTextColumn;

      // Create the DataGridTextBoxColumn with the PropertyDescriptor and Format.
      myColumnTextColumn = gcnew DataGridTextBoxColumn( pd,fmt->SortableDateTimePattern );

      // Add the new DataGridColumnStyle to the GridColumnsCollection.
      dataGrid1->TableStyles[ 0 ]->GridColumnStyles->Add( myColumnTextColumn );
   }
private void AddColumn(DataTable myTable){
    // Add a new DataColumn to the DataTable.
    DataColumn myColumn = new DataColumn("myTextBoxColumn");
    myColumn.DataType = typeof(String);
    myColumn.DefaultValue="default string";
    myTable.Columns.Add(myColumn);
    // Get the ListManager for the DataTable.
    CurrencyManager cm = (CurrencyManager)this.BindingContext[myTable];
    // Use the ListManager to get the PropertyDescriptor for the new column.
    PropertyDescriptor pd = cm.GetItemProperties()["myTextBoxColumn"];
    // Create a new DataTimeFormat object.
    DateTimeFormatInfo fmt = new DateTimeFormatInfo();
    // Insert code to set format.
    DataGridTextBoxColumn myColumnTextColumn;
    // Create the DataGridTextBoxColumn with the PropertyDescriptor and Format.
    myColumnTextColumn = new DataGridTextBoxColumn(pd, fmt.SortableDateTimePattern);
    // Add the new DataGridColumnStyle to the GridColumnsCollection.
    dataGrid1.TableStyles[0].GridColumnStyles.Add(myColumnTextColumn);
 }

Private Sub AddColumn(myTable As DataTable)
    ' Add a new DataColumn to the DataTable.
    Dim myColumn As New DataColumn("myTextBoxColumn")
    myColumn.DataType = GetType(String)
    myColumn.DefaultValue = "default string"
    myTable.Columns.Add(myColumn)
    ' Get the ListManager for the DataTable.
    Dim cm As CurrencyManager = CType(Me.BindingContext(myTable), CurrencyManager)
    ' Use the ListManager to get the PropertyDescriptor for the new column.
    Dim pd As PropertyDescriptor = cm.GetItemProperties()("myTextBoxColumn")
    ' Create a new DataTimeFormat object.
    Dim fmt As New DateTimeFormatInfo()
    ' Insert code to set format.
    Dim myColumnTextColumn As DataGridTextBoxColumn
    ' Create the DataGridTextBoxColumn with the PropertyDescriptor and Format.
    myColumnTextColumn = New DataGridTextBoxColumn(pd, fmt.SortableDateTimePattern)
    ' Add the new DataGridColumnStyle to the GridColumnsCollection.
    dataGrid1.TableStyles(0).GridColumnStyles.Add(myColumnTextColumn)
End Sub

注解

DataGridColumnStyle使用 PropertyDescriptor 来确定列中显示的数据的类型。The DataGridColumnStyle uses a PropertyDescriptor to determine the type of data displayed in the column. 若要返回 PropertyDescriptorCollection ,请使用 GetItemProperties 类的方法 BindingManagerBaseTo return a PropertyDescriptorCollection, use the GetItemProperties method of the BindingManagerBase class.

另请参阅

适用于

DataGridTextBoxColumn(PropertyDescriptor, Boolean)

使用指定的 DataGridTextBoxColumn 初始化 PropertyDescriptor 类的新实例。Initializes a new instance of the DataGridTextBoxColumn class using the specified PropertyDescriptor. 指定 DataGridTextBoxColumn 是否为默认列。Specifies whether the DataGridTextBoxColumn is a default column.

public:
 DataGridTextBoxColumn(System::ComponentModel::PropertyDescriptor ^ prop, bool isDefault);
public DataGridTextBoxColumn (System.ComponentModel.PropertyDescriptor prop, bool isDefault);
new System.Windows.Forms.DataGridTextBoxColumn : System.ComponentModel.PropertyDescriptor * bool -> System.Windows.Forms.DataGridTextBoxColumn
Public Sub New (prop As PropertyDescriptor, isDefault As Boolean)

参数

isDefault
Boolean

指定 DataGridTextBoxColumn 是否为默认列。Specifies whether the DataGridTextBoxColumn is a default column.

注解

DataGridColumnStyle使用 PropertyDescriptor 来确定列中显示的数据的类型。The DataGridColumnStyle uses a PropertyDescriptor to determine the type of data displayed in the column. 若要返回 PropertyDescriptorCollection ,请使用 GetItemProperties 类的方法 BindingManagerBaseTo return a PropertyDescriptorCollection, use the GetItemProperties method of the BindingManagerBase class.

适用于

DataGridTextBoxColumn(PropertyDescriptor, String)

使用指定的 DataGridTextBoxColumn 和格式初始化 PropertyDescriptor 的一个新实例。Initializes a new instance of a DataGridTextBoxColumn with the specified PropertyDescriptor and format.

public:
 DataGridTextBoxColumn(System::ComponentModel::PropertyDescriptor ^ prop, System::String ^ format);
public DataGridTextBoxColumn (System.ComponentModel.PropertyDescriptor prop, string format);
new System.Windows.Forms.DataGridTextBoxColumn : System.ComponentModel.PropertyDescriptor * string -> System.Windows.Forms.DataGridTextBoxColumn
Public Sub New (prop As PropertyDescriptor, format As String)

参数

prop
PropertyDescriptor

PropertyDescriptor 将关联的列的 DataGridTextBoxColumnThe PropertyDescriptor for the column with which the DataGridTextBoxColumn will be associated.

format
String

用于格式化列值的格式。The format used to format the column values.

示例

下面的代码示例演示如何使用此成员。The following code example demonstrates the use of this member.

private:
   void MyAddCustomDataTableStyle()
   {
      // Get the currency manager for 'myDataSet'.
      CurrencyManager^ myCurrencyManger = dynamic_cast<CurrencyManager^>(this->BindingContext[ myDataSet ]);
      DataGridTableStyle^ myTableStyle = gcnew DataGridTableStyle;
      myTableStyle->MappingName = "Customers";
      PropertyDescriptor^ proprtyDescriptorName = myCurrencyManger->GetItemProperties()[ "CustName" ];
      DataGridColumnStyle^ myCustomerNameStyle = gcnew DataGridTextBoxColumn( proprtyDescriptorName );
      myCustomerNameStyle->MappingName = "custName";
      myCustomerNameStyle->HeaderText = "Customer Name";
      myTableStyle->GridColumnStyles->Add( myCustomerNameStyle );

      // Add style for 'Date' column.
      PropertyDescriptor^ myDateDescriptor = myCurrencyManger->GetItemProperties()[ "Date" ];

      // 'G' is for MM/dd/yyyy HH:mm:ss date format.
      DataGridColumnStyle^ myDateStyle = gcnew DataGridTextBoxColumn( myDateDescriptor,"G" );
      myDateStyle->MappingName = "Date";
      myDateStyle->HeaderText = "Date";
      myDateStyle->Width = 150;
      myTableStyle->GridColumnStyles->Add( myDateStyle );

      // Add DataGridTableStyle instances to GridTableStylesCollection.
      myDataGrid->TableStyles->Add( myTableStyle );
   }

private void MyAddCustomDataTableStyle()
{
   // Get the currency manager for 'myDataSet'.
   CurrencyManager myCurrencyManger =
            (CurrencyManager)this.BindingContext[myDataSet];

   DataGridTableStyle myTableStyle = new DataGridTableStyle();
   myTableStyle.MappingName = "Customers";

   PropertyDescriptor proprtyDescriptorName =
            myCurrencyManger.GetItemProperties()["CustName"];

   DataGridColumnStyle myCustomerNameStyle =
            new DataGridTextBoxColumn(proprtyDescriptorName);

   myCustomerNameStyle.MappingName = "custName";
   myCustomerNameStyle.HeaderText = "Customer Name";
   myTableStyle.GridColumnStyles.Add(myCustomerNameStyle);

   // Add style for 'Date' column.
   PropertyDescriptor myDateDescriptor =
            myCurrencyManger.GetItemProperties()["Date"];
   // 'G' is for MM/dd/yyyy HH:mm:ss date format.
   DataGridColumnStyle myDateStyle =
            new DataGridTextBoxColumn(myDateDescriptor,"G");

   myDateStyle.MappingName = "Date";
   myDateStyle.HeaderText = "Date";
   myDateStyle.Width = 150;
   myTableStyle.GridColumnStyles.Add(myDateStyle);

   // Add DataGridTableStyle instances to GridTableStylesCollection.
   myDataGrid.TableStyles.Add(myTableStyle);
}

Private Sub MyAddCustomDataTableStyle()
   ' Get the currency manager for 'myDataSet'.
   Dim myCurrencyManger As CurrencyManager = CType(Me.BindingContext(myDataSet), CurrencyManager)
   
   Dim myTableStyle As New DataGridTableStyle()
   myTableStyle.MappingName = "Customers"
   
   Dim proprtyDescriptorName As PropertyDescriptor = myCurrencyManger.GetItemProperties()("CustName")
   
   Dim myCustomerNameStyle As DataGridTextBoxColumn = New DataGridTextBoxColumn(proprtyDescriptorName)
   
   myCustomerNameStyle.MappingName = "custName"
   myCustomerNameStyle.HeaderText = "Customer Name"
   myTableStyle.GridColumnStyles.Add(myCustomerNameStyle)
   
   ' Add style for 'Date' column.
   Dim myDateDescriptor As PropertyDescriptor = myCurrencyManger.GetItemProperties()("Date")
   ' 'G' is for MM/dd/yyyy HH:mm:ss date format.
   Dim myDateStyle As DataGridTextBoxColumn = New DataGridTextBoxColumn(myDateDescriptor, "G")
   
   myDateStyle.MappingName = "Date"
   myDateStyle.HeaderText = "Date"
   myDateStyle.Width = 150
   myTableStyle.GridColumnStyles.Add(myDateStyle)
   
   ' Add DataGridTableStyle instances to GridTableStylesCollection.
   myDataGrid.TableStyles.Add(myTableStyle)
End Sub


注解

使用此构造函数可为显示的数据创建自定义格式。Use this constructor to create a custom format for the displayed data.

DataGridColumnStyle使用 PropertyDescriptor 来确定列中显示的数据的类型。The DataGridColumnStyle uses a PropertyDescriptor to determine the type of data displayed in the column. 若要返回 PropertyDescriptorCollection ,请使用 GetItemProperties 类的方法 BindingManagerBaseTo return a PropertyDescriptorCollection, use the GetItemProperties method of the BindingManagerBase class.

有关设置字符格式的详细信息,请参阅 格式设置类型自定义日期和时间格式字符串For more information about formatting characters, see Formatting Types and Custom Date and Time Format Strings.

另请参阅

适用于

DataGridTextBoxColumn(PropertyDescriptor, String, Boolean)

使用指定的 DataGridTextBoxColumn 和格式初始化 PropertyDescriptor 类的新实例。Initializes a new instance of the DataGridTextBoxColumn class with a specified PropertyDescriptor and format. 指定此列是否为默认列。Specifies whether the column is the default column.

public:
 DataGridTextBoxColumn(System::ComponentModel::PropertyDescriptor ^ prop, System::String ^ format, bool isDefault);
public DataGridTextBoxColumn (System.ComponentModel.PropertyDescriptor prop, string format, bool isDefault);
new System.Windows.Forms.DataGridTextBoxColumn : System.ComponentModel.PropertyDescriptor * string * bool -> System.Windows.Forms.DataGridTextBoxColumn
Public Sub New (prop As PropertyDescriptor, format As String, isDefault As Boolean)

参数

format
String

使用的格式。The format used.

isDefault
Boolean

指定 DataGridTextBoxColumn 是否为默认列。Specifies whether the DataGridTextBoxColumn is the default column.

注解

DataGridColumnStyle使用 PropertyDescriptor 来确定列中显示的数据的类型。The DataGridColumnStyle uses a PropertyDescriptor to determine the type of data displayed in the column. 若要返回 PropertyDescriptorCollection ,请使用 GetItemProperties 类的方法 BindingManagerBaseTo return a PropertyDescriptorCollection, use the GetItemProperties method of the BindingManagerBase class.

适用于