Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call DataGridTableStyle member in runtime

Status
Not open for further replies.

ljCharlie

IS-IT--Management
Apr 21, 2003
397
0
0
US
I have three datasets that uses one datagrid to display the data. I need to format this datagrid to fit each dataset. However, I couldn't figure out how. Here's what I found out so far. In the DataGridTableStyle Collection Editor, I have created three members: 0, 1, 2. In each of these members, I have defined a GridColumnStyles collection in DataGridColumnStyle Collection Editor their properties. The problem I have right now is how do I call the DataGridTableStyle member at run time. I have three datasets that uses the same datagrid that is why I have three members in the DataGridTableStyle. But I can not figure out how to call the member that will correspond with a dataset that it is bind to the datagrid. Any help to do this task is greatly appreciated!

ljCharlie
 
1) define the tablestyles
Private tableStyle1 As New DataGridTableStyle()
Private tableStyle2 As New DataGridTableStyle()
Private tableStyle3 As New DataGridTableStyle()

2) In form Load event save the table styles which u added in the design mode
tableStyle1 = dgEntrySearchResult.TableStyles.Item(0)
tableStyle2 = dgEntrySearchResult.TableStyles.Item(1)
tableStyle3 = dgEntrySearchResult.TableStyles.Item(2)

3) whenever you want to swithc it use
'the following will switch to first tablestyle
dgEntrySearchResult.TableStyles.Clear()
dgEntrySearchResult.TableStyles.Add(tableStyle1)


Regards
Nouman

Nouman Zaheer
Software Engineer
MSR
 
Thanks! I'll give that a try.

ljCharlie
 
It doesn't work. There is no error but all the formating I did in the DataGridTableStyle Collection Editor never showed up in the datagrid. The Header Text mapping, width, alignment and so on...never appear in the datagrid.

ljCharlie
 
I think it has to do with the dataset, datadapter, or datagrid setting at design time. The code you gave me works because I have tried with a different project and it work just fine. However, I'm not sure what other settings do I need to check because it's not working.

ljCharlie
 
Charlie
it works fine with me ,you just have to set the TableStyle at design time and then switch the tablestyle whenever u want its nothing to do with datasource
Take carez
Nouman

Nouman Zaheer
Software Engineer
MSR
 
Thank you very much for your help. I'm greatly appreciated. Unfornately it's still not working. In a way it is involve with the datasource. Because the member under DataGridTableStyle Collection Editor has to be mapped correctly to the database table. I tested, if I only have one dataset and assign that dataset to the datagrid.datasource during design time then it work, because I was able to click on the members properties MappingName in DataGridTableStyle Collection Editor and select the table name. The problem arrises when I have more than one dataset because the MappingName in DataGridTableStyle Collection Editor doesn't know which table to map correctly. Although I did specify a MappingName to each member in the DataGridTableStyle Collection Editor, it's still doesn't work. Here's what I did in the code to clear, fill, specify the datasource, and switch the tablestyle.

dim tbl As New DataTable()
DataSetComputer.Reset()
DataSetComputer.Clear()
tbl = DataSetComputer.Tables.Add("Computer")
tbl = DataSetComputer.Computer
DataAdapterComputer.Fill(tbl)
datagridComputer.DataSource = tbl
datagridComputer.TableStyles.Clear()
datagridComputer.TableStyles.Add(tableStyleComputer)

ljCharlie
 
Dear Charlie
Table Style has nothing to do with DataSource,As far as the tecnique i give u it will work becuase its working for me
but what you are doing wrong is binding the DATASET to the gird at design time remove that thing and bind the DataSet at run-time and
Make three TableStyles at design time with manually adding the DataBoundColumn (Collection) with the same Mapping Name you need to have as with the DataSet
Hope you understand what i means ,don't bind the grid to dataset at design,and bind it at run-time with TableStyle at design time with manually added databound column
The main idea is that u will be abel to switch to that TableStyle at any point at run-time and its done with the steps i told you...
Hope it will help you out
Regards
Nouman

Nouman Zaheer
Software Engineer
MSR
 
Thanks it works now. I'm not quite sure why...but it works.

Again, thank you very much!

ljCharlie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top