Freigeben über


DataGridTextBoxColumn-Konstruktor (PropertyDescriptor, String)

Initialisiert eine neue Instanz einer DataGridTextBoxColumn mit dem angegebenen PropertyDescriptor und Format.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public Sub New ( _
    prop As PropertyDescriptor, _
    format As String _
)
'Usage
Dim prop As PropertyDescriptor
Dim format As String

Dim instance As New DataGridTextBoxColumn(prop, format)
public DataGridTextBoxColumn (
    PropertyDescriptor prop,
    string format
)
public:
DataGridTextBoxColumn (
    PropertyDescriptor^ prop, 
    String^ format
)
public DataGridTextBoxColumn (
    PropertyDescriptor prop, 
    String format
)
public function DataGridTextBoxColumn (
    prop : PropertyDescriptor, 
    format : String
)

Parameter

  • format
    Das zum Formatieren der Spaltenwerte verwendete Format.

Hinweise

Mit diesem Konstruktor können Sie ein benutzerdefiniertes Format für die angezeigten Daten erstellen.

Der DataGridColumnStyle verwendet einen PropertyDescriptor, um den Typ der Daten zu bestimmen, die in der Spalte angezeigt werden. Verwenden Sie die GetItemProperties-Methode der BindingManagerBase-Klasse, um eine PropertyDescriptorCollection zurückzugeben.

Weitere Informationen zum Formatieren von Zeichen finden Sie unter Formatzeichenfolgen für Datum und Uhrzeit und Standardmäßige Zahlenformatzeichenfolgen.

Beispiel

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 'MyAddCustomDataTableStyle

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:
   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.get_BindingContext().get_Item(myDataSet)));
    DataGridTableStyle myTableStyle = new DataGridTableStyle();

    myTableStyle.set_MappingName("Customers");

    PropertyDescriptor proprtyDescriptorName = 
        myCurrencyManger.GetItemProperties().get_Item("CustName");
    DataGridColumnStyle myCustomerNameStyle = 
        new DataGridTextBoxColumn(proprtyDescriptorName);

    myCustomerNameStyle.set_MappingName("custName");
    myCustomerNameStyle.set_HeaderText("Customer Name");
    myTableStyle.get_GridColumnStyles().Add(myCustomerNameStyle);

    // Add style for 'Date' column.
    PropertyDescriptor myDateDescriptor = 
        myCurrencyManger.GetItemProperties().get_Item("Date");

    // 'G' is for MM/dd/yyyy HH:mm:ss date format.
    DataGridColumnStyle myDateStyle = 
        new DataGridTextBoxColumn(myDateDescriptor, "G");

    myDateStyle.set_MappingName("Date");
    myDateStyle.set_HeaderText("Date");
    myDateStyle.set_Width(150);
    myTableStyle.get_GridColumnStyles().Add(myDateStyle);

    // Add DataGridTableStyle instances to GridTableStylesCollection.
    myDataGrid.get_TableStyles().Add(myTableStyle);
} //MyAddCustomDataTableStyle
private void MyAddCustomDataTableStyle()
{
    // Get the currency manager for 'myDataSet'.
    CurrencyManager myCurrencyManger = ((CurrencyManager)
        (this.get_BindingContext().get_Item(myDataSet)));
    DataGridTableStyle myTableStyle = new DataGridTableStyle();

    myTableStyle.set_MappingName("Customers");

    PropertyDescriptor proprtyDescriptorName = 
        myCurrencyManger.GetItemProperties().get_Item("CustName");
    DataGridColumnStyle myCustomerNameStyle = 
        new DataGridTextBoxColumn(proprtyDescriptorName);

    myCustomerNameStyle.set_MappingName("custName");
    myCustomerNameStyle.set_HeaderText("Customer Name");
    myTableStyle.get_GridColumnStyles().Add(myCustomerNameStyle);

    // Add style for 'Date' column.
    PropertyDescriptor myDateDescriptor = 
        myCurrencyManger.GetItemProperties().get_Item("Date");

    // 'G' is for MM/dd/yyyy HH:mm:ss date format.
    DataGridColumnStyle myDateStyle = 
        new DataGridTextBoxColumn(myDateDescriptor, "G");

    myDateStyle.set_MappingName("Date");
    myDateStyle.set_HeaderText("Date");
    myDateStyle.set_Width(150);
    myTableStyle.get_GridColumnStyles().Add(myDateStyle);

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

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

DataGridTextBoxColumn-Klasse
DataGridTextBoxColumn-Member
System.Windows.Forms-Namespace
DataColumn
DataGridColumnStyle-Klasse
DataGrid-Klasse