eggy
eggy

Reputation: 2844

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?

Upvotes: 6

Views: 3468

Answers (2)

Libor
Libor

Reputation: 3303

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

betterListView.Columns[0].MinimumWidth = 50;

There is also MaximumWidth and AllowResize.

Upvotes: 0

Chris Love
Chris Love

Reputation: 120

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;
     }
}

Upvotes: 5

Related Questions