Populates the grid with data from a data source.
[Visual Basic] Public Sub PopulateColumns() [C#] public void PopulateColumns(); [C++] public: void PopulateColumns(); [JScript] public function PopulateColumns();
You must invoke this method after making changes to the DataGridTable in order to see the changes in the control, especially after making changes to the data schema contained by the DataGridTable or the column schema contained by GridColumns. For example, if you add a DataColumn to the DataGridTable, you must invoke the PopulateColumns method to cause the new column to display.
Resetting the DataSource property automatically invokes the PopulateColumns method.
The following example adds a DataColumn to an existing DataTable, and invokes PopulateColumns method to display the new column.
[Visual Basic]
Private Sub AddColumn() Dim t As DataTable Dim c As DataColumn ' Presuming the DataGrid is bound to a DataTable t = CType(DataGrid1.Source, DataTable) ' Create a new Column. c = New DataColumn("myNewColumn") ' Add the column to the DataTable t.Columns.Add(c) ' Invoke PopulateColumns to display the column. DataGrid1.PopulateColumns End Sub
DataGrid Class | DataGrid Members | System.WinForms Namespace | DataColumn | DataGridTable | DataSource | DataTable