J
John Edens
Mona, if you are out there, your advice for how to programmatically populate
a datagrid control worked great,
HOWEVER,
I'm trying to use DataGridTableStyle and DataGridColumnStyle objects to
format cell contents with no luck.
I notice in all the examples I've been able to find, the first step is to
assign a mapping name to the new DataGridTableStyle. For example:
Dim tableStyle as New DataGridTableStyle()
TableStyle.MappingName = "Projects"
Which, I assume, tells the DataGrid to use that table style when the Data
Source for the table is the "Projects" database table.
The code I use to populate the DataGrid (which came from Mona) is below. I
am trying to figure out what MappingName I would use for the
DataGridTableStyle in this instance. Thanks for any help!
Dim Tbl As New DataTable
'This is the column type which will be added to the Datatable
Dim Col1 As New DataColumn
Dim Col2 As New DataColumn
Dim Col3 As New DataColumn
'Declare a procedure to format the datatable
Private Sub FormatGrid()
'Define column 1
'Specify the column data type
Col1.DataType = System.Type.GetType("System.Int32")
'This name is to identify the column
Col1.ColumnName = "No"
'This will enable automatically increment the data
Col1.AutoIncrement = True
'This value will be displayed in the header of the column
Col1.Caption = "No"
'This will make this column read only,Since it is autoincrement
Col1.ReadOnly = True
'Now add this column to the datatable
Tbl.Columns.Add(Col1)
'Repeat the same procedure
'Define Column 2
Col2.DataType = System.Type.GetType("System.String")
Col2.ColumnName = "Name"
Col2.Caption = "Name"
Col2.ReadOnly = False
Tbl.Columns.Add(Col2)
'Define Column 3
Col3.DataType = System.Type.GetType("System.String")
Col3.ColumnName = "Address"
Col3.Caption = "Address"
Col3.ReadOnly = False
Tbl.Columns.Add(Col3)
'BIND THE DATATABLE TO THE DATAGRID
DataGrid1.DataSource = Tbl
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'now call this procedure in the load event of the form
FormatGrid()
'To add rows dynamically in the click event of the button,
'include the code in the click event of the btnAdd
'Create a row type variable
Dim r As DataRow
'Add a new row
r = Tbl.NewRow()
'Specify the col name to add value for the row
r("Name") = "ManojRajan"
r("Address") = "New Delhi"
'Add the row to the tabledata
Tbl.Rows.Add(r)
End Sub
a datagrid control worked great,
HOWEVER,
I'm trying to use DataGridTableStyle and DataGridColumnStyle objects to
format cell contents with no luck.
I notice in all the examples I've been able to find, the first step is to
assign a mapping name to the new DataGridTableStyle. For example:
Dim tableStyle as New DataGridTableStyle()
TableStyle.MappingName = "Projects"
Which, I assume, tells the DataGrid to use that table style when the Data
Source for the table is the "Projects" database table.
The code I use to populate the DataGrid (which came from Mona) is below. I
am trying to figure out what MappingName I would use for the
DataGridTableStyle in this instance. Thanks for any help!
Dim Tbl As New DataTable
'This is the column type which will be added to the Datatable
Dim Col1 As New DataColumn
Dim Col2 As New DataColumn
Dim Col3 As New DataColumn
'Declare a procedure to format the datatable
Private Sub FormatGrid()
'Define column 1
'Specify the column data type
Col1.DataType = System.Type.GetType("System.Int32")
'This name is to identify the column
Col1.ColumnName = "No"
'This will enable automatically increment the data
Col1.AutoIncrement = True
'This value will be displayed in the header of the column
Col1.Caption = "No"
'This will make this column read only,Since it is autoincrement
Col1.ReadOnly = True
'Now add this column to the datatable
Tbl.Columns.Add(Col1)
'Repeat the same procedure
'Define Column 2
Col2.DataType = System.Type.GetType("System.String")
Col2.ColumnName = "Name"
Col2.Caption = "Name"
Col2.ReadOnly = False
Tbl.Columns.Add(Col2)
'Define Column 3
Col3.DataType = System.Type.GetType("System.String")
Col3.ColumnName = "Address"
Col3.Caption = "Address"
Col3.ReadOnly = False
Tbl.Columns.Add(Col3)
'BIND THE DATATABLE TO THE DATAGRID
DataGrid1.DataSource = Tbl
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'now call this procedure in the load event of the form
FormatGrid()
'To add rows dynamically in the click event of the button,
'include the code in the click event of the btnAdd
'Create a row type variable
Dim r As DataRow
'Add a new row
r = Tbl.NewRow()
'Specify the col name to add value for the row
r("Name") = "ManojRajan"
r("Address") = "New Delhi"
'Add the row to the tabledata
Tbl.Rows.Add(r)
End Sub