Reputation: 4302
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.
Upvotes: 1
Views: 3393
Reputation: 4302
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.
Upvotes: 0
Reputation: 1062865
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...
Upvotes: 3