Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What's Wrong With This Code?
Message
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01386784
Message ID:
01386846
Views:
44
Hi Viv,

We want this column width to be a difference between grid's width and the rest of the columns total width. The direct solution would be to sum the rest of the columns and then subtruct it from grid's width. Or, you're right, we can just add the delta to the existing width.

>>>I have a grid which displays a checkbook register. The total width of all the columns is less than the total width of the grid, so I want to resize the TransDesc column to fill it in:
>>>
>>>
>>>int iColumnWidths = 0;
>>>foreach (DataGridViewColumn oCol in grdRegister.Columns)
>>>{
>>>    iColumnWidths = iColumnWidths + oCol.Width;
>>>}
>>>grdRegister.Columns["TransDesc"].Width = grdRegister.Width - iColumnWidths;
>>>
>>>
>>>The TransDesc.Width value is negative.
>>
>>Is TransDesc column part of the grdRegister.Columns? If yes, it's included into the calculation and then, of course, the width would become negative.
>
>Huh? If the total width of the columns IS less than the width of the grid then 'grdRegister.Width - iColumnsWidths' should be positive
>
>>You need to exclude if with if code from the loop.
>You wouldn't need to exclude it from the loop - just add the free space to its existing width:
grdRegister.Columns["TransDesc"].Width += (grdRegister.Width - iColumnWidths);
>
>Best,
>Viv
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform