Freigeben über


DataGridTextBoxColumn-Klasse

Fungiert als Host für ein TextBox-Steuerelement zum Bearbeiten von Zeichenfolgen in einer Zelle eines DataGridColumnStyle.

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

Syntax

'Declaration
Public Class DataGridTextBoxColumn
    Inherits DataGridColumnStyle
'Usage
Dim instance As DataGridTextBoxColumn
public class DataGridTextBoxColumn : DataGridColumnStyle
public ref class DataGridTextBoxColumn : public DataGridColumnStyle
public class DataGridTextBoxColumn extends DataGridColumnStyle
public class DataGridTextBoxColumn extends DataGridColumnStyle

Hinweise

Die DataGridTextBoxColumn-Klasse wird von der abstract-Klasse DataGridColumnStyle abgeleitet. Zur Laufzeit fungiert die DataGridTextBoxColumn als Host für ein DataGridTextBox-Steuerelement, mit dem Benutzer Text bearbeiten können.

Zu den speziellen der Klasse hinzugefügten Eigenschaften gehören Format und HideEditBox. Diese Eigenschaften ermöglichen den Zugriff auf das gehostete DataGridTextBox-Steuerelement und dessen Attribute und legen das Format zum Anzeigen von Werten fest.

Wenn die Datenquelle eine DataTable mit DataColumn-Objekten ist, sollte die DataType-Eigenschaft der DataColumn auf einen Datentyp festgelegt werden, der in einem Textfeld-Steuerelement logisch bearbeitet werden kann. Folgende Datentypen sind einer DataGridTextBoxColumn automatisch zugeordnet: Byte, DateTime, Decimal, Double, Int16, Int32, Int64, UInt16, UInt32, UInt64, Single und String.

Hinweis

Folgende Typen werden von Visual Basic nicht vollständig unterstützt: DateTime, UInt16, UInt32, UInt64 und TimeSpan. (Operatoren sind nicht zulässig.)

Beispiel

Im folgenden Beispiel wird eine DataGridTextBoxColumn erstellt und der GridColumnStylesCollection hinzugefügt. Damit dieses Codebeispiel ausgeführt werden kann, müssen Sie den voll gekennzeichneten Assemblynamen bereitstellen. Informationen über das Abrufen des voll gekennzeichneten Assemblynamens finden Sie unter Assemblynamen.

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 'AddColumn
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:
   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.set_DataType(System.Type.GetType("System.String"));
    myColumn.set_DefaultValue("default string");
    myTable.get_Columns().Add(myColumn);
    // Get the CurrencyManager for the DataTable.
    CurrencyManager cm = (CurrencyManager)(this.get_BindingContext().
        get_Item(myTable));
    // Use the CurrencyManager to get the PropertyDescriptor 
    // for the new column.
    PropertyDescriptor pd = cm.GetItemProperties().
        get_Item("myTextBoxColumn");
    DataGridTextBoxColumn myColumnTextColumn;

    // Create the DataGridTextBoxColumn with the PropertyDescriptor.
    myColumnTextColumn = new DataGridTextBoxColumn(pd);

    // Add the new DataGridColumn to the GridColumnsCollection.
    dataGrid1.set_DataSource(myTable);
    dataGrid1.get_TableStyles().Add(new DataGridTableStyle());
    dataGrid1.get_TableStyles().get_Item(0).
        get_GridColumnStyles().Add(myColumnTextColumn);
} //AddColumn

Vererbungshierarchie

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.DataGridColumnStyle
        System.Windows.Forms.DataGridTextBoxColumn

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

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

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

DataGridTextBoxColumn-Member
System.Windows.Forms-Namespace
DataGridBoolColumn-Klasse
DataGridColumnStyle-Klasse
DataColumn
DataType
DataGrid-Klasse
DataGridTextBox-Klasse
TextBox