DataGridview column resizing issue

I have a datagridview where users can select which subset of columns to view. The problem I am facing is that when changing the displayed columns, the width of the columns is only determined by the width of the header cells, not the data in it. I have each column set to AutoSizeMode = AllCells.

If a new row is added, the columns become correct. But when the set of columns changes, the width values ​​are wrong.

+1


source to share


2 answers


Hmm ... can't say I've seen this myself, but (as a workaround) you could try to switch the resizing mode after changing the columns:

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

      



Worth a try...

+3


source


A simpler option was to remove and add columns to add all columns and then just selectively hide / show the set of columns you want. The other method did work though.



0


source







All Articles