I have a listview with a series of columns, but I would like to hide some, how do I do this?
I have a listview with a series of columns, but I would like to hide some, how do I do this?
It seems like ListView
works similar to TabControl
, where it is not possible to set a Visible
property.
However when you add a column to ListView
, it is also an object within your Form, which can be accessed by the defined name.
In the example, I used a listView
and added 3 columns, then I remove and add the column named columnHeader2
:
//Removendo
if (listView1.Columns.Contains(columnHeader2))
listView1.Columns.Remove(columnHeader2);
//Adicionando
if (!listView1.Columns.Contains(columnHeader2))
{
listView1.Columns.Add(columnHeader2);
//Defino a posição dela novamente, caso contrário ela estará na última coluna.
columnHeader2.DisplayIndex = 1;
}
I think only by setting the column Width to 0, which will hide it.
seuListView.Columns[indiceDaColuna].Width = 0;