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....
+1
A:
Google says http://www.codeproject.com/KB/cpp/LVHeaderSubclass.aspx
and http://www.codeproject.com/KB/list/myListViewNoSize.aspx
Midhat
2010-03-17 06:47:00
+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
2010-03-17 07:08:07
thanks so much it was really helpful..
zoya
2010-03-17 08:26:54
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
2010-03-17 11:48:33
OMG, I didn't know about Ctrl-Numpad-+
Zenya
2010-03-17 11:56:20
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
2010-03-17 11:43:51
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
2010-08-01 07:36:16