DataGridTextBox.SetDataGrid(DataGrid) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
public:
void SetDataGrid(System::Windows::Forms::DataGrid ^ parentGrid);
public void SetDataGrid (System.Windows.Forms.DataGrid parentGrid);
member this.SetDataGrid : System.Windows.Forms.DataGrid -> unit
Public Sub SetDataGrid (parentGrid As DataGrid)
Parameters
Examples
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 );
}
// 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 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
Applies to
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET