Sdílet prostřednictvím


DataGridTextBoxColumn Konstruktory

Definice

Inicializuje novou instanci DataGridTextBoxColumn třídy.

Přetížení

DataGridTextBoxColumn()

Inicializuje novou instanci DataGridTextBoxColumn třídy.

DataGridTextBoxColumn(PropertyDescriptor)

Inicializuje novou instanci DataGridTextBoxColumn třídy se zadaným PropertyDescriptor.

DataGridTextBoxColumn(PropertyDescriptor, Boolean)

Inicializuje novou instanci DataGridTextBoxColumn třídy pomocí zadané PropertyDescriptor. Určuje, jestli DataGridTextBoxColumn je výchozí sloupec.

DataGridTextBoxColumn(PropertyDescriptor, String)

Inicializuje novou instanci DataGridTextBoxColumn třídy se zadaným PropertyDescriptor a formátem.

DataGridTextBoxColumn(PropertyDescriptor, String, Boolean)

Inicializuje novou instanci DataGridTextBoxColumn třídy se zadaným PropertyDescriptor a formátem. Určuje, jestli je sloupec výchozím sloupcem.

DataGridTextBoxColumn()

Inicializuje novou instanci DataGridTextBoxColumn třídy.

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

Příklady

Následující příklad vytvoří DataGridTextBoxColumn a přidá ho GridColumnStylesCollection do kolekce.

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

Viz také

Platí pro

DataGridTextBoxColumn(PropertyDescriptor)

Inicializuje novou instanci DataGridTextBoxColumn třídy se zadaným 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)

Parametry

prop
PropertyDescriptor

Sloupec PropertyDescriptor , ke kterému DataGridTextBoxColumn bude přidružen.

Příklady

Následující příklad vytvoří DataGridTextBoxColumn a přidá ho GridColumnStylesCollection do kolekce.

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

Poznámky

Slouží DataGridColumnStyle PropertyDescriptor k určení typu dat zobrazených ve sloupci. Pokud chcete vrátit PropertyDescriptorCollectionmetodu třídy, použijte GetItemProperties metodu BindingManagerBase .

Viz také

Platí pro

DataGridTextBoxColumn(PropertyDescriptor, Boolean)

Inicializuje novou instanci DataGridTextBoxColumn třídy pomocí zadané PropertyDescriptor. Určuje, jestli DataGridTextBoxColumn je výchozí sloupec.

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)

Parametry

isDefault
Boolean

Určuje, jestli DataGridTextBoxColumn je výchozí sloupec.

Poznámky

Slouží DataGridColumnStyle PropertyDescriptor k určení typu dat zobrazených ve sloupci. Pokud chcete vrátit PropertyDescriptorCollectionmetodu třídy, použijte GetItemProperties metodu BindingManagerBase .

Platí pro

DataGridTextBoxColumn(PropertyDescriptor, String)

Inicializuje novou instanci DataGridTextBoxColumn třídy se zadaným PropertyDescriptor a formátem.

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)

Parametry

prop
PropertyDescriptor

Sloupec PropertyDescriptor , ke kterému DataGridTextBoxColumn bude přidružen.

format
String

Formát použitý k formátování hodnot sloupců.

Příklady

Následující příklad kódu ukazuje použití tohoto člena.

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

Poznámky

Tento konstruktor použijte k vytvoření vlastního formátu pro zobrazená data.

Slouží DataGridColumnStyle PropertyDescriptor k určení typu dat zobrazených ve sloupci. Pokud chcete vrátit PropertyDescriptorCollectionmetodu třídy, použijte GetItemProperties metodu BindingManagerBase .

Další informace o formátování znaků najdete v tématu Typy formátování a vlastní řetězce formátu data a času.

Viz také

Platí pro

DataGridTextBoxColumn(PropertyDescriptor, String, Boolean)

Inicializuje novou instanci DataGridTextBoxColumn třídy se zadaným PropertyDescriptor a formátem. Určuje, jestli je sloupec výchozím sloupcem.

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)

Parametry

format
String

Použitý formát.

isDefault
Boolean

Určuje, jestli DataGridTextBoxColumn je výchozí sloupec.

Poznámky

Slouží DataGridColumnStyle PropertyDescriptor k určení typu dat zobrazených ve sloupci. Pokud chcete vrátit PropertyDescriptorCollectionmetodu třídy, použijte GetItemProperties metodu BindingManagerBase .

Platí pro