Hello,
I need to populate a datagrid a second time. The first time it is populated works perfect. However, when I click on the button that populates it a second time I get this error:
THE DATA GRID STYLES COLLECTION ALREADY CONTAINS A TABLE STYLE WITH THE SAME MAPPING NAME!
The reason I need to populate the grid a second time is that the data is a result of a stored procedure that has two dates as parameters. If one of those date changes, the data will change also.
Thanks in advance for any help you provide. I've read some really good advice/pointers/help/tek-tips in this forum. Thank you for that too.
Rudy
I need to populate a datagrid a second time. The first time it is populated works perfect. However, when I click on the button that populates it a second time I get this error:
THE DATA GRID STYLES COLLECTION ALREADY CONTAINS A TABLE STYLE WITH THE SAME MAPPING NAME!
Code:
' Code that fills the dataset
Grid1.DataSource = dataset.Tables(0)
' Apply new TableStyles to DataGrid
Dim dgStyle1 As New DataGridTableStyle
dgStyle1.MappingName = dataset.Tables(0).ToString
' First column (Key field in table)
Dim dgTextCol As New DataGridTextBoxColumn
dgTextCol.MappingName = "Key"
dgTextCol.HeaderText = "Key"
dgTextCol.Width = 0
' Add dgTextCol text box column to dgStyle table style
dgStyle1.GridColumnStyles.Add(dgTextCol)
' Second column (Field in table)
dgTextCol = New DataGridTextBoxColumn
dgTextCol.MappingName = "Col1"
dgTextCol.HeaderText = "Col1"
dgTextCol.Width = 150
dgStyle1.GridColumnStyles.Add(dgTextCol)
' Third column (field in table)
dgTextCol = New DataGridTextBoxColumn
dgTextCol.MappingName = "Col2"
dgTextCol.HeaderText = "Col2"
dgTextCol.Width = 100
dgStyle1.GridColumnStyles.Add(dgTextCol)
' Forth column (field in table)
dgTextCol = New DataGridTextBoxColumn
dgTextCol.MappingName = "Col3"
dgTextCol.HeaderText = "Col3"
dgTextCol.Width = 100
dgStyle1.GridColumnStyles.Add(dgTextCol)
' Fifth column (field in table)
dgTextCol = New DataGridTextBoxColumn
dgTextCol.MappingName = "Col4"
dgTextCol.HeaderText = "Col4"
dgTextCol.Width = 200
dgStyle1.GridColumnStyles.Add(dgTextCol)
' Second column (field in table)
dgTextCol = New DataGridTextBoxColumn
dgTextCol.MappingName = "Col5"
dgTextCol.HeaderText = "Col5"
dgTextCol.Width = 100
dgStyle1.GridColumnStyles.Add(dgTextCol)
'******** This next line of code is where the error occurs when the button is clicked and the grid is already populated.
Grid1.TableStyles.Add(dgStyle1)
The reason I need to populate the grid a second time is that the data is a result of a stored procedure that has two dates as parameters. If one of those date changes, the data will change also.
Thanks in advance for any help you provide. I've read some really good advice/pointers/help/tek-tips in this forum. Thank you for that too.
Rudy