>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. You need to exclude if with if code from the loop.
If it's not broken, fix it until it is.
My Blog