Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What's Wrong With This Code?
Message
De
10/03/2009 04:05:07
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01386784
Message ID:
01386835
Vues:
41
>>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform