How to hide a column in a ListView control?

后端 未结 9 2325
慢半拍i
慢半拍i 2021-02-14 03:01

How can I hide a column in a ListView control, without setting the column Width property to 0?

Also, can I lock the Width

相关标签:
9条回答
  • 2021-02-14 03:15

    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.

    0 讨论(0)
  • 2021-02-14 03:17

    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.

    0 讨论(0)
  • 2021-02-14 03:19

    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

    0 讨论(0)
  • 2021-02-14 03:19

    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.

    0 讨论(0)
  • 2021-02-14 03:27

    If you need associate data with a row without displaying it use the ListView's Tag property

    0 讨论(0)
  • 2021-02-14 03:31

    Go to Edit Columns (under properties of listview in design mode), under Misc set Width to ZERO

    0 讨论(0)
提交回复
热议问题