Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>How to hide/show listview columns</strong></p> <p><em>C#, .NET framework 3.5.</em></p> <p>It is easy to hide and show listview columns, if you use the listview in “virtual mode”. In “virtual mode”, you are responsible for filling the listviewitems with data. This makes it possible to put the correct data in the correct column.</p> <p>Let me demonstrate: Create a form, and add a listview control and a button control. Add 3 columns to the listview control. Set the “view” property of the listview control to “Details”. Set the “VirtualMode” property of the listview control to “True”. Set the “VirtualListSize” property of the listview control to “100”. Add a bool to the form:</p> <pre><code>private bool mblnShow = true; </code></pre> <p>Add the event “RetrieveVirtualItem” for the listview control, and add the following code:</p> <pre><code>ListViewItem objListViewItem = new ListViewItem(); objListViewItem.Text = "Item index: " + e.ItemIndex.ToString(); if (mblnShow) objListViewItem.SubItems.Add("second column: " + DateTime.Now.Millisecond.ToString()); objListViewItem.SubItems.Add("third column: " + DateTime.Now.Millisecond.ToString()); e.Item = objListViewItem; </code></pre> <p>Add the “Click” event for the button control, and add the following code:</p> <pre><code>mblnShow = !mblnShow; if (mblnShow &amp;&amp; !this.listView1.Columns.Contains(this.columnHeader2)) this.listView1.Columns.Insert(1, this.columnHeader2); else if (!mblnShow &amp;&amp; this.listView1.Columns.Contains(this.columnHeader2)) this.listView1.Columns.Remove(this.columnHeader2); </code></pre> <p>Run the application, and press the button to show and hide the second column.</p> <p>Please note that running a listview in virtual mode will throw an error if you put data in the items collection. There is much more the know about virtual mode, so I suggest reading about it before using it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload