views:

1301

answers:

2

I have a datagridview where the users can select which subset of columns to view. The problem I am having is that when I change the columns being displayed, the column widths are only being determined by the width of the Header Cells, not the data in it. I do have each column set to AutoSizeMode = AllCells.

If a new row is added, the columns become the correct width. But when the set of columns is changed, the widths are wrong.

+2  A: 

Hmm... can't say I've seen that myself, but (as a workaround) you could try toggling the resize mode after you change the columns:

dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

Worth a try...

Marc Gravell
A: 

The easier option was rather then removing and adding the columns was to add all of the columns and then just selectively hide/show the desired set of columns. Although the other method did work.

Ross Goddard