Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Form listview minimum column width

I have the application look like it stops the width at 50, but if the mouse is dragged further on and then let up, the width will be below:

private void ListView1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
    if (e.ColumnIndex ==0 & e.NewWidth <50)
    {
        e.Cancel = true;
    }
}

I cannot work out how to force the ColumnWidthChanged width to 50 if the changed width = < 50. I don't need to fix the column widths, as information will vary in length, but force a minimum width.

Any suggestions?

like image 576
eggy Avatar asked Jan 09 '13 00:01

eggy


1 Answers

If you want to change the Width after the user has finished dragging the column separator you can do this

private const int _minimumColumnWidth = 50;

private void ListView1_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
{
     if (ListView1.Columns[e.ColumnIndex].Width < _minimumColumnWidth)
     {
          ListView1.Columns[e.ColumnIndex].Width = _minimumColumnWidth;
     }
}
like image 154
Chris Love Avatar answered Nov 09 '22 19:11

Chris Love