DataGridView - user sizing columns

P

proxyuser

I have AllowUserToResizeColumns = true. AutoSizeColumnsMode is set to
AllCells. When the grid is displayed with data, the columns are not
resizable with the mouse. Any ideas?
 
J

Jack Jackson

I have AllowUserToResizeColumns = true. AutoSizeColumnsMode is set to
AllCells. When the grid is displayed with data, the columns are not
resizable with the mouse. Any ideas?

If you set AutoSizeColumnsMode to AllCells, then each cell will always
be the width necessary to display and it makes no sense to allow the
user to resize the columns since they are constrained to be a fixed
size.

It depends what you want to do. I suppose you want the grid columns
to initially be sized to exactly fit the data, but then allow the user
to later change it.

What I usually do is to set the columns that are relatively narrow to
AllCells, and the larger ones to size to a percentage of the remaining
space, which allows the user to change those columns.
 
P

proxyuser

Jack Jackson said:
It depends what you want to do. I suppose you want the grid columns
to initially be sized to exactly fit the data, but then allow the user
to later change it.

Exactly. I didn't know AllCells constrained it.
What I usually do is to set the columns that are relatively narrow to
AllCells, and the larger ones to size to a percentage of the remaining
space, which allows the user to change those columns.

The grid is showing dynamic data, and I don't know that columns or sizes at
dev time. Also, we'll be virtualizing it, so I don't really want to waste
much run time calculating all the column data widths.
 
J

Jack Jackson

Exactly. I didn't know AllCells constrained it.


The grid is showing dynamic data, and I don't know that columns or sizes at
dev time. Also, we'll be virtualizing it, so I don't really want to waste
much run time calculating all the column data widths.

Then I wouldn't autosize to the size of the current data. Instead I
would make a guess as to which columns need to be wider than others
and set each to a proportion of the grid width.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top