>>Tim,
>>
>>That's exactly what I tried yesterday. I tried to wrap the check for null in IF statement and let the rest of the code run.
>>
>>It didn't work when I called it for the second grid.
>>
>>Can you explain me briefly what the code above was exactly doing and why I can not apply the same style on multiple grids?
>>
>>Thanks again.
>
>
>OK, a couple of new thoughts. Your code is actually creating table styles with fixed values. DataGridTableStyles are added to a collection of the grid and can be changed at runtime. What I have done in my applications is create the different table styles I intend to use and then just dynamically change which one I want. So for instance you could just create your table styles for each of your grids at design time and then just switch between them at runtime. Here is a method I use in one of my apps to switch between styles.
>
>private void SetMapping(DataGridTableStyle ts)
>{
> int row = this.dgRouteEvents.CurrentRowIndex;
>
> foreach(DataGridTableStyle dgts in this.dgRouteEvents.TableStyles)
> {
> dgts.MappingName = "";
> }
>
> ts.MappingName = "RouteEvents";
>
> this.dgRouteEvents.CurrentRowIndex = row;
> DataGridFunctions.SelectCurrentRow(this.dgRouteEvents);
>}
>
>
>I call it in a button method like this.
>
>private void btnShowDesc_Click(object sender, System.EventArgs e)
>{
> SetMapping(this.tsActDesc);
>}
>
>
>Mappings can be created and added to the collection in code like this.
>
>private void CreateCustomDataTableStyle()
>{
> // Create DataGridTableStyle and set its Mapping Name
> DataGridTableStyle tableStyle1 = new DataGridTableStyle();
> tableStyle1.MappingName = "MapNameOne";
> // Set all the things I want on this one here
>
> // Create another one
> DataGridTableStyle tableStyle2 = new DataGridTableStyle();
> tableStyle2.MappingName = "MapNameTwo";
> // Set all the things I want on this one here
>
> // Add these to the Grids collection
> dgMyGrid.TableStyles.Add(tableStyle1);
> dgMyGrid.TableStyles.Add(tableStyle2);
>}
>
>Tim
Ok, one more question:
Here
> // Add these to the Grids collection
> dgMyGrid.TableStyles.Add(tableStyle1);
> dgMyGrid.TableStyles.Add(tableStyle2);
can you do instead
> dgMyGrid.TableStyles.Add(tableStyle1);
> dgMyDifferentGrid.TableStyles.Add(tableStyle1);
in other words, apply the same tablestyle to two different grids?
If it's not broken, fix it until it is.
My Blog