DataGridTextBox.SetDataGrid 方法

DataGrid 设置为此 TextBox 控件所属项。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Sub SetDataGrid ( _
    parentGrid As DataGrid _
)
用法
Dim instance As DataGridTextBox
Dim parentGrid As DataGrid

instance.SetDataGrid(parentGrid)
public void SetDataGrid (
    DataGrid parentGrid
)
public:
void SetDataGrid (
    DataGrid^ parentGrid
)
public void SetDataGrid (
    DataGrid parentGrid
)
public function SetDataGrid (
    parentGrid : DataGrid
)

参数

  • parentGrid
    承载该控件的 DataGrid 控件。

示例

' Create a DataSet with a table and populate it.
Private Sub MakeDataSet()
   myDataSet = New DataSet("myDataSet")
   Dim tPer As New DataTable("Person")
   Dim cPerName As New DataColumn("PersonName")

   tPer.Columns.Add(cPerName)
   myDataSet.Tables.Add(tPer)

   Dim newRow1 As DataRow
   Dim i As Integer
   For i = 1 To 5
      newRow1 = tPer.NewRow()
      tPer.Rows.Add(newRow1)
   Next i

   tPer.Rows(0)("PersonName") = "Robert"
   tPer.Rows(1)("PersonName") = "Michael"
   tPer.Rows(2)("PersonName") = "John"
   tPer.Rows(3)("PersonName") = "Walter"
   tPer.Rows(4)("PersonName") = "Simon"

   ' Bind the 'DataSet' to the 'DataGrid'.
   myDataGrid.SetDataBinding(myDataSet, "Person")
   myDataGridTextBox.DataBindings.Add("Text", myDataSet, "Person.PersonName")
   ' Set the DataGrid to the DataGridTextBox.
   myDataGridTextBox.SetDataGrid(myDataGrid)
End Sub 'MakeDataSet
// Create a DataSet with a table and populate it.
private void MakeDataSet()
{
   myDataSet = new DataSet("myDataSet");

   DataTable tPer = new DataTable("Person");

   DataColumn cPerName = new DataColumn("PersonName");
   tPer.Columns.Add(cPerName);

   myDataSet.Tables.Add(tPer);

   DataRow newRow1;

   for(int i = 1; i < 6; i++)
   {
      newRow1 = tPer.NewRow();
      tPer.Rows.Add(newRow1);
   }

   tPer.Rows[0]["PersonName"] = "Robert";
   tPer.Rows[1]["PersonName"] = "Michael";
   tPer.Rows[2]["PersonName"] = "John";
   tPer.Rows[3]["PersonName"] = "Walter";
   tPer.Rows[4]["PersonName"] = "Simon";

   // Bind the 'DataSet' to the 'DataGrid'.
   myDataGrid.SetDataBinding(myDataSet, "Person");
   myDataGridTextBox.DataBindings.Add("Text",myDataSet,"Person.PersonName");
   // Set the DataGrid to the DataGridTextBox.
   myDataGridTextBox.SetDataGrid(myDataGrid);
}
   // Create a DataSet with a table and populate it.
private:
   void MakeDataSet()
   {
      myDataSet = gcnew DataSet( "myDataSet" );
      DataTable^ tPer = gcnew DataTable( "Person" );
      DataColumn^ cPerName = gcnew DataColumn( "PersonName" );
      tPer->Columns->Add( cPerName );
      myDataSet->Tables->Add( tPer );
      DataRow^ newRow1;
      for ( int i = 1; i < 6; i++ )
      {
         newRow1 = tPer->NewRow();
         tPer->Rows->Add( newRow1 );
      }
      tPer->Rows[ 0 ][ "PersonName" ] = "Robert";
      tPer->Rows[ 1 ][ "PersonName" ] = "Michael";
      tPer->Rows[ 2 ][ "PersonName" ] = "John";
      tPer->Rows[ 3 ][ "PersonName" ] = "Walter";
      tPer->Rows[ 4 ][ "PersonName" ] = "Simon";

      // Bind the 'DataSet' to the 'DataGrid'.
      myDataGrid->SetDataBinding( myDataSet, "Person" );
      myDataGridTextBox->DataBindings->Add( "Text", myDataSet, "Person::PersonName" );

      // Set the DataGrid to the DataGridTextBox.
      myDataGridTextBox->SetDataGrid( myDataGrid );
   }
// Create a DataSet with a table and populate it.
private void MakeDataSet()
{
    myDataSet = new DataSet("myDataSet");

    DataTable tPer = new DataTable("Person");
    DataColumn cPerName = new DataColumn("PersonName");

    tPer.get_Columns().Add(cPerName);
    myDataSet.get_Tables().Add(tPer);

    DataRow newRow1;

    for (int i = 1; i < 6; i++) {
        newRow1 = tPer.NewRow();
        tPer.get_Rows().Add(newRow1);
    }

    tPer.get_Rows().get_Item(0).set_Item("PersonName", "Robert");
    tPer.get_Rows().get_Item(1).set_Item("PersonName", "Michael");
    tPer.get_Rows().get_Item(2).set_Item("PersonName", "John");
    tPer.get_Rows().get_Item(3).set_Item("PersonName", "Walter");
    tPer.get_Rows().get_Item(4).set_Item("PersonName", "Simon");

    // Bind the 'DataSet' to the 'DataGrid'.
    myDataGrid.SetDataBinding(myDataSet, "Person");
    myDataGridTextBox.get_DataBindings().Add("Text", myDataSet, 
        "Person.PersonName");

    // Set the DataGrid to the DataGridTextBox.
    myDataGridTextBox.SetDataGrid(myDataGrid);
} //MakeDataSet

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

DataGridTextBox 类
DataGridTextBox 成员
System.Windows.Forms 命名空间