DataGridTextBox::SetDataGrid Method (DataGrid^)

 

Sets the DataGrid to which this TextBox control belongs.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public:
void SetDataGrid(
	DataGrid^ parentGrid
)

Parameters

parentGrid
Type: System.Windows.Forms::DataGrid^

The DataGrid control that hosts the control.

The following code example demonstrates the use of this member.

   // 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 );
   }

.NET Framework
Available since 1.1
Return to top
Show: