开发者

DataGridView resizeable columns, but last column can't be resized bigger?

For c = 0 To grd.Columns.Count - 1
    grd.Columns(c).Resizable = DataGridViewTriState.True
Next c

That allows all the columns in my DataGridView to be resizable EXCEPT the last column. Why? I DO get the little resizable-mouse-pointer... but you can only make the column SMALLER, never WIDER.

(Same problem if I try to set all the columns to Resizable, using the VB.net IDE)

What am I doing wrong here? Shouldn't I be able to resize ANY column I开发者_开发技巧 want, bigger or smaller?


You can't make the last column wider because it's already filling all of the available space in the control!

Unlike the other columns in the middle, which simply steal space from the column to their right, there is no column to the right of the last column for it to steal space from. Since it doesn't have anywhere to go, the control simply prevents you from resizing the last column.


I've had the same problem - I couldn't resize the last column in DataGridView (the resizable property was set to 'True'). I've had 'Fill mode' set to 'Displayed Cells'. When I've changed that setting to 'Not set', I can normally resize the last column.


What you probably want is for the user to resize the left edge of last column, not to be able to resize the right edge of the last column.

One option is to set the AutoSizeMode of the last column to 'Fill' and the other columns to some other mode, like 'Not Set'. Doing this would make it so that when you resize the right edge of the second-to-last column, then the left edge of the last column will automatically fill-in that space.


Why not add an extra column set to width of zero, so that the user can resize the last one you really want to display? I know it's kinda kludgy! If you care, you could probably the resizable property = false of the extra zero length cell to not allow resize. That method wasn't working properly for me. Required binding the last field to something, or else the field before it (which was my last column before adding the fake one in) would not allow resize.

For me the problem was caused by me changing the AutoSizeMode property of my last column to AllCells (which was a DataGridViewTextBoxColumn) at the suggestion of a fix to make a multicollumn textbox. But this didn't work the way I needed it to work, so I had did it a different way (by creating a dynamic textbox and putting it where I wanted it, but had left the AutoSizeMode = AllCells.

When I set AutroSizeMode = NotSet on my Last Column, then the DataGridView allows the user to resize this last column now!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜