Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataGridView virtual mode column divider double click autosize

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.

like image 604
Fraga Avatar asked May 10 '14 17:05

Fraga


1 Answers

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;
}
like image 148
dE fENDER Avatar answered Sep 28 '22 09:09

dE fENDER