Minimum column width in a Windows Form

I have an application that looks like it stops the width at 50, but if the mouse drags further and then is omitted, the width will be lower:

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

I cannot figure out how to force the width of ColumnWidthChanged to 50 if changed width = < 50 . I do not need to fix the width of the columns, as the information will vary in length, and the strength of the minimum width.

Any suggestions?

+4
source share
2 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; } } 
+3
source

Better ListView and Better ListView Express (free) components have some of these useful properties in column headers:

 betterListView.Columns[0].MinimumWidth = 50; 

There is also MaximumWidth and AllowResize .

-1
source

All Articles