How can I hide a column in a ListView
control, without setting the column Width
property to 0
?
Also, can I lock the Width
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.
The simplest way as follows, try this code segment :
hide:
LVW.Columns.Item(0).Width = 0
show again:
LVW.Columns.Item(0).AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent)
may this help someone.
You should use DataTemplateSelector to hide and show dynamically a column or a row in a listview. There is an intersting article in the official documentation. https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/templates/data-templates/selector
If you have only one column, a second empty column shows up to fill the extra space to the right. To hide this empty column, implement the listview resize event. In there do the following.
m_lstItems.Columns[0].Width = m_lstItems.Width - 5;
This will effecitvely hide the extra empty column and instead have the first column take up all the space in the listview.
If you need associate data with a row without displaying it use the ListView's Tag property
Go to Edit Columns (under properties of listview in design mode), under Misc set Width to ZERO