DataGridView virtual mode column divider double click autosize

1.5k views Asked by At

I have a winform applicaction with a DataGridView in Virtual mode, everything is working great! the only problem is that when i hit double click en a column divider, the control is trying to fit the column width to all cells, not only the displayed or visible! And obviously that hangs the app.

I have try all kind of configurations

AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCellsExceptHeader;
AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;

Everything!, settings in the datagrid and in each column! and nothing works

Any idea?

The final result is: User being able to resize the columns, but not by giving double click en de column border!.. i dont care if it doesnt fit at all.

1

There are 1 answers

0
dE fENDER On

You should process ColumnDividerDoubleClick this way:

private void datagridview_ColumnDividerDoubleClick(object sender, DataGridViewColumnDividerDoubleClickEventArgs e)
{
  if (e.Button == MouseButtons.Left)
  {
    datagridview.AutoResizeColumn(e.ColumnIndex, DataGridViewAutoSizeColumnMode.DisplayedCells);
  }
  e.Handled = true;
}