views:

667

answers:

4

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....

+3  A: 

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;
}
Zenya
thanks so much it was really helpful..
zoya
This is yet another example of why using a ListView is so hard -- it's hard to get everything right. This code will not catch attempts resize columns via the keyboard, most notably Ctrl-Numpad-+. That will resize all your columns to minimum calculated width, even with this event handler in place. After they have been resized, the user won't be able to put them back again.
Grammarian
OMG, I didn't know about Ctrl-Numpad-+
Zenya
A: 

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.

Grammarian
A: 

Thanks a lot I've used it in vb.net as

 Private Sub ListView1_ColumnWidthChanging(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnWidthChangingEventArgs) Handles ListView1.ColumnWidthChanging
     e.Cancel = True
     e.NewWidth = ListView1.Columns(e.ColumnIndex).Width    
 End Sub
Rakesh Kumar