sard0nicpan
Programmer
I am able to set custom column styles for one datagrid, however, I cannot make it work for more than one. The code that works for datagrid1 is below:
I call the Fx with the lines from the following subRoutine:
So OK, I call my second DataGrid(2) in much the same way:
And I duplicate the second "MakeITWork2" Function:
So I figure, well Tables(0) is for DataGrid1, so maybe Tables(1) is for DataGrid(2):
Well as you can tell, I am being overly logical here. So how do I create a new table, and bind the DataGrid2 , 3, & 4 data to it? I am more used to VBA now than anything else. Where did I go wrong?
Thanks in advance,
SP
Code:
Function MakeItWork1(ByVal mdst As DataSet)
'Apply new TableStyles to DataGrid
Dim dgStyle1 As New DataGridTableStyle
dgStyle1.MappingName = mdst.Tables(0).ToString
'First Column (UBID field in my table)
Dim dgTextCol As New DataGridTextBoxColumn
dgTextCol.MappingName = "UBID" 'Name of field in the table
dgTextCol.HeaderText = "UBID"
dgTextCol.Width = 50
'Add dgTextCol text box column to dgStyle table style
dgStyle1.GridColumnStyles.Add(dgTextCol)
'Second Column (Batch field in my table)
dgTextCol = New DataGridTextBoxColumn
dgTextCol.MappingName = "Batch Name"
dgTextCol.HeaderText = "Batch Name"
dgTextCol.Width = 100
dgStyle1.GridColumnStyles.Add(dgTextCol)
'Third Column (Date field in my table)
dgTextCol = New DataGridTextBoxColumn
dgTextCol.MappingName = "Date Scanned"
dgTextCol.HeaderText = "Date Scanned"
dgTextCol.Width = 120
dgStyle1.GridColumnStyles.Add(dgTextCol)
'
'FourthColumn (Upload field in my table)
dgTextCol = New DataGridTextBoxColumn
dgTextCol.MappingName = "Uploaded"
dgTextCol.HeaderText = "Uploaded"
dgTextCol.Width = 150
dgStyle1.GridColumnStyles.Add(dgTextCol)
'Add the dgStyle style to the DataGridTableStyle
DataGrid1.TableStyles.Add(dgStyle1)
End Function
I call the Fx with the lines from the following subRoutine:
Code:
Me.DataGrid1.DataSource = grst.Tables(0)
Call MakeItWork1(grst)
So OK, I call my second DataGrid(2) in much the same way:
Code:
Me.DataGrid2.DataSource = grst.Tables(0)
Call MakeItWork1(grst)
And I duplicate the second "MakeITWork2" Function:
Code:
Function MakeItWork2(ByVal mdst As DataSet)
'Apply new TableStyles to DataGrid
Dim dgStyle2 As New DataGridTableStyle
dgStyle2.MappingName = mdst.Tables(0) 'POINT OF ERROR:THE DATA GRID STYLES COLLECTION ALREADY CONTAINS A TABLE STYLE WITH THE SAME MAPPING NAME!
'First Column (Index field in my table)
Dim dgTextCol As New DataGridTextBoxColumn
dgTextCol.MappingName = "Index" 'Name of field in the table
dgTextCol.HeaderText = "Voucher #"
dgTextCol.Width = 75
' etc and so on
So I figure, well Tables(0) is for DataGrid1, so maybe Tables(1) is for DataGrid(2):
Code:
dgStyle2.MappingName = mdst.Tables(1) ' ERROR: CANNOT FIND TABLE . . .
Well as you can tell, I am being overly logical here. So how do I create a new table, and bind the DataGrid2 , 3, & 4 data to it? I am more used to VBA now than anything else. Where did I go wrong?
Thanks in advance,
SP