Aan Aan - 3 months ago 30
C# Question

How to hide a column in a ListView control?

How can I hide a column in a

ListView
control, without setting the column
Width
property to
0
?

Also, can I lock the
Width
of a column?

Answer

Not very clear what matters here C++Cli tag, but:

I presume that if you're talking about a columns in ListView, you're in details view of the control. There is no builtin Hide/Show column way in ListView, as much as I'm aware of, so one of solutions can be just remove that column form UI.

To do that in most smooth way possible just call your ListView column regeneration code in between

listView.SuspendLayout(true);

/*Manipulate column here*/

listView.ResumeLayout();

The data which is visible on ListView always remains "in your hands", so at the moment you will decide to show the column again, just show the column and fill ListView again.

Hope this helps.