Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to fix the column width of a listview in c# windows form?

i have a listview i need to fix the column width of the listview so that at run time user cannot drag the columnheaders and resize it.....what is the procedure?? i have searched all the properties but none of them help me out to solve this pbm.. this is possible in gridview but how will it be possible in listview....

like image 891
zoya Avatar asked Dec 03 '22 13:12

zoya


2 Answers

The easiest way is to use ColumnWidthChanging event:

private void listView_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
    e.Cancel = true;
    e.NewWidth = listView.Columns[e.ColumnIndex].Width;
}
like image 114
Zenya Avatar answered Jan 13 '23 14:01

Zenya


Use ObjectListView. That not only allows individual columns to be fixed width, but to have minimum and maximum widths as well. It does the hard work of catching all cases, including Ctrl-Numpad-+, so that they cannot be circumvented.

like image 30
Grammarian Avatar answered Jan 13 '23 14:01

Grammarian