Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can I format two grids using the same GridItem?
Message
From
21/05/2009 10:05:20
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01401161
Message ID:
01401279
Views:
27
>>>Unfortunately, obviously it only formats the first grid and not the second. How can I made this code generic enough to call multiple times?
>>>
>>>Thanks a lot in advance.
>>
>>What do you mean by "it only formats the first grid but not the second"? Are you calling this method twice passing in the first grid and then the second on a second pass? If you always want to format both grids at the same time then make another method to call this one twice.
>>
>>private void FormatGrids()
>>{
>>     this.FormatOrderDetailsGrid(dtFirstTable, grdFirstGrid);
>>     this.FormatOrderDetailsGrid(dtSecondTable, grdSecondGrid);
>>}
>>
>>Tim
>
>Tim,
>
>Do you see this code at the top of my method:
>
>if (_gridStyleItem == null)
>>            {
>>                _gridStyleItem = new DataGridTableStyle();
>
>
>Obviously, only the first time the _gridStyleItem is null, so it only formats anything once. I don't know how to modify this code to let it work multiple times, I'm not very familiar with how formatting is done in Windows Forms DataGrids. I tried to change the top portion to be
>if (_gridStyleItem == null)
>> {
>> _gridStyleItem = new DataGridTableStyle();
> }
>
>and then the rest of the code, but I got another error with this. So, it looks like I had to duplicate this code using yet another variable for _gridStyleItemView, unless there is a work around here.
>
>Thanks again.

I don't know enough about what it is your re-formating is for or how many times this gets called, but you could create a different TableStyle reference for each grid and pass that in also. If you need a different one each time you run this method, then I would guess you could create a new one. Also, if you need to re-format an existing one even if it already exists then I would not wrap all this code inside the if statement. Just wrap the creation of the DataGridTableStyle inside the if so it gets created only if it doesn't exist. I would do that anyway since if this method is called or re-called for the same grid, there is no reason not to run your format code. Maybe another method altered it differently and now you need to put it back. You know your needs, so if any of those comments help.
Good luck
Tim
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform