Wednesday, September 14, 2011

Add a table and column to a DataGrid programmatically

Bind a DataGrid control to a DataSet. After, declare a new TableStyle and set its name.

Dim ts1 As New DataGridTableStyle()
ts1.MappingName = "Laptops"


Declare a new column style and after set its name and other properties.

Dim myDataCol As New DataGridBoolColumn()
myDataCol.HeaderText = "New Column"
myDataCol.MappingName = "Laptop"


Call the Add method of the GridColumnStylesCollection object to add the column to the table style


ts1.GridColumnStyles.Add(myDataCol)
Call the Add method of the GridTableStylesCollection object to add the table style to the data grid.

DataGrid1.TableStyles.Add(ts1)

No comments:

Post a Comment

There was an error in this gadget