Modifier

Partager via


DataGridTextBoxColumn Constructors

Definition

Initializes a new instance of the DataGridTextBoxColumn class.

Overloads

DataGridTextBoxColumn()

Initializes a new instance of the DataGridTextBoxColumn class.

DataGridTextBoxColumn(PropertyDescriptor)

Initializes a new instance of the DataGridTextBoxColumn class with a specified PropertyDescriptor.

DataGridTextBoxColumn(PropertyDescriptor, Boolean)

Initializes a new instance of the DataGridTextBoxColumn class using the specified PropertyDescriptor. Specifies whether the DataGridTextBoxColumn is a default column.

DataGridTextBoxColumn(PropertyDescriptor, String)

Initializes a new instance of the DataGridTextBoxColumn class with the specified PropertyDescriptor and format.

DataGridTextBoxColumn(PropertyDescriptor, String, Boolean)

Initializes a new instance of the DataGridTextBoxColumn class with a specified PropertyDescriptor and format. Specifies whether the column is the default column.

DataGridTextBoxColumn()

Initializes a new instance of the DataGridTextBoxColumn class.

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

Examples

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

See also

Applies to

DataGridTextBoxColumn(PropertyDescriptor)

Initializes a new instance of the DataGridTextBoxColumn class 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)

Parameters

prop
PropertyDescriptor

The PropertyDescriptor for the column with which the DataGridTextBoxColumn will be associated.

Examples

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

Remarks

The DataGridColumnStyle uses a PropertyDescriptor to determine the type of data displayed in the column. To return a PropertyDescriptorCollection, use the GetItemProperties method of the BindingManagerBase class.

See also

Applies to

DataGridTextBoxColumn(PropertyDescriptor, Boolean)

Initializes a new instance of the DataGridTextBoxColumn class using the specified PropertyDescriptor. 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)

Parameters

prop
PropertyDescriptor

The PropertyDescriptor to be associated with the DataGridTextBoxColumn.

isDefault
Boolean

Specifies whether the DataGridTextBoxColumn is a default column.

Remarks

The DataGridColumnStyle uses a PropertyDescriptor to determine the type of data displayed in the column. To return a PropertyDescriptorCollection, use the GetItemProperties method of the BindingManagerBase class.

Applies to

DataGridTextBoxColumn(PropertyDescriptor, String)

Initializes a new instance of the DataGridTextBoxColumn class 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)

Parameters

prop
PropertyDescriptor

The PropertyDescriptor for the column with which the DataGridTextBoxColumn will be associated.

format
String

The format used to format the column values.

Examples

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

Remarks

Use this constructor to create a custom format for the displayed data.

The DataGridColumnStyle uses a PropertyDescriptor to determine the type of data displayed in the column. To 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.

See also

Applies to

DataGridTextBoxColumn(PropertyDescriptor, String, Boolean)

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)

Parameters

prop
PropertyDescriptor

The PropertyDescriptor to be associated with the DataGridTextBoxColumn.

format
String

The format used.

isDefault
Boolean

Specifies whether the DataGridTextBoxColumn is the default column.

Remarks

The DataGridColumnStyle uses a PropertyDescriptor to determine the type of data displayed in the column. To return a PropertyDescriptorCollection, use the GetItemProperties method of the BindingManagerBase class.

Applies to