cschristian78
Technical User
I have about 10 queries that I run based on what the user selects in a listbox. Those 10 queries can be put into 1 of 3 catagories: LP1, LP2 and LP3. Each catagory has a different number of columns. For example, I run a query that is in cat LP1 which may have 4 columns. I then select another entry in the listbox which calls a query from the LP2 catagory. This query may have 3 of the same columns from the LP1 query but may also contain a couple more. When I then select another query that goes back to the four column query, I have nulls in the additional two columns. I would like to remove the additional columns. I assume that I need to use the DataGridTableStyle. When setting that up, I get "The data grid table styles collection already contains a table style with the same mapping name execption. I am unsure how to make the mapping name unique. Here is the following code. (LP2 and LP3 have the same code outside of the query and all tables, tablestyles are the same except the number eg dgtsLP1 vs dgtsLP2 vs dgtsLP3). Thanks
Public Sub FillGrid_LP1()
Dim dgtsLP1 As New DataGridTableStyle()
'Clear data in Dataset
Try
dgtsLP1.Dispose()
dsGrid.Tables("dtLP1").Clear()
Catch
Exit Try
End Try
'Create Profile for specified type
daLP.SelectCommand = New SqlClient.SqlCommand(Query, ProfDataCon)
Try
dgtsLP1.MappingName = lstbxProfiles.SelectedItem(0).ToString
'Fill Dataset
daLP.Fill(dsGrid, "dtLP1")
'fill DataGrid by setting bindings
dgrdResults.DataSource = dsGrid.Tables("dtLP1")
dgrdResults.TableStyles.Add(dgtsLP1)
dgrdResults.CaptionText = lstbxProfiles.SelectedItem(0).ToString
Catch ex As Exception
daLP.Fill(dsGrid, "dtLP1")
'fill DataGrid by setting bindings
dgrdResults.DataSource = dsGrid.Tables("dtLP1")
dgrdResults.CaptionText = lstbxProfiles.SelectedItem(0).ToString
'MessageBox.Show(ex.ToString)
End Try
End Sub
Public Sub FillGrid_LP1()
Dim dgtsLP1 As New DataGridTableStyle()
'Clear data in Dataset
Try
dgtsLP1.Dispose()
dsGrid.Tables("dtLP1").Clear()
Catch
Exit Try
End Try
'Create Profile for specified type
daLP.SelectCommand = New SqlClient.SqlCommand(Query, ProfDataCon)
Try
dgtsLP1.MappingName = lstbxProfiles.SelectedItem(0).ToString
'Fill Dataset
daLP.Fill(dsGrid, "dtLP1")
'fill DataGrid by setting bindings
dgrdResults.DataSource = dsGrid.Tables("dtLP1")
dgrdResults.TableStyles.Add(dgtsLP1)
dgrdResults.CaptionText = lstbxProfiles.SelectedItem(0).ToString
Catch ex As Exception
daLP.Fill(dsGrid, "dtLP1")
'fill DataGrid by setting bindings
dgrdResults.DataSource = dsGrid.Tables("dtLP1")
dgrdResults.CaptionText = lstbxProfiles.SelectedItem(0).ToString
'MessageBox.Show(ex.ToString)
End Try
End Sub