Preventing the user to resize the ListView columns
-
Hi, I have a ListView in details view and I would like to prevent the user to resize the column widths. Thanks in advance.
-
Hi, I have a ListView in details view and I would like to prevent the user to resize the column widths. Thanks in advance.
does it have a ColumnWidthChanging event? and would that support canceling? :)
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
-
does it have a ColumnWidthChanging event? and would that support canceling? :)
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
Yes it has and supports canceling but user can change the width even it's canceled. Just the resizing animation isn't shown.
-
Yes it has and supports canceling but user can change the width even it's canceled. Just the resizing animation isn't shown.
SimpleData wrote:
Yes it has and supports canceling but user can change the width even it's canceled. Just the resizing animation isn't shown.
You can use the ColumnWidthChanging [^]event of the listview. But surprisingly, it seems to have a bug which MS has accepted. You can have a look here[^]. A possible workaround would be to cancel the event, and set the old width again. (kinda dirty...)
private void listView1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
e.NewWidth = this.listView1.Columns[e.ColumnIndex].Width;
e.Cancel = true;
}Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
Yes it has and supports canceling but user can change the width even it's canceled. Just the resizing animation isn't shown.
The trick is to also set the
NewWidth
property to the existingWidth
:private void listView_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
e.NewWidth = listView.Columns[e.ColumnIndex].Width;
e.Cancel = true;
}[Edit] Manas posted whilst I was posting! :laugh: [/Edit]
Dave
Generic BackgroundWorker - My latest article!
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
The trick is to also set the
NewWidth
property to the existingWidth
:private void listView_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
e.NewWidth = listView.Columns[e.ColumnIndex].Width;
e.Cancel = true;
}[Edit] Manas posted whilst I was posting! :laugh: [/Edit]
Dave
Generic BackgroundWorker - My latest article!
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus)Thank you all. Workaround works like a charm. :D