We help IT Professionals succeed at work.

Listview(report mode): hiding but not removing columns

TheMadManiac
TheMadManiac asked
on
Hi,

I have a sweet little ListView in report mode with 5 columns, does all i need from it. However i would like to be able to use the right-mousekey on a column header to display a popup menu with the column names, so i can hide or unhide the columns.

I tried using the width property set to 0, but then its not hidden, just small (and you can make it big again).

Any insight on how this is done will be appreciated, however if you make a small how-to (enough detail, but not a click-here click-there thing) how this _all_ can be done you earns 400 points.

Just a little "this and that property" gets the current points :)

Cheers,

 Tam
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2012

Commented:
Instead of using a right click, you can use the ColumnClick method which is fired when the left key is clicked on a Column Header.

As you have discovered there is no way to remove a column.  The ColumnHeaders object has a Remove method, but his only removes the Column Header and the last column of data.  We will have to wait for VB.NET to be able to remove columns:  the ListView control has a RemoveAt method for this purpose.  In the meantime you may want to double check setting the column width to 0, as it appears to work for me:  I cannot "make it big again".

Here is my code:

Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)

ListView1.ColumnHeaders(ColumnHeader.Index).Width = 0

End Sub

Author

Commented:
That will work :)

Post as answer please.

Tam
CERTIFIED EXPERT
Top Expert 2012
Commented:
Again, no need to post as answer.  You can award points to anybody who has commented.

Anthony

Commented:
I wasted 10 points because I thought this question had a proper answer. The columns can be resized. even if they are set to 0 width.
CERTIFIED EXPERT
Top Expert 2012

Commented:
Absolutely.  Here is what you have to do:

ListView1.ColumnHeaders(ColumnHeader.Index).Width = 100

This will re-size the column.

Anthony

Commented:
I mean the user can actually resize the listview. Even if it's width is set to 0. it is hard to explain.

When you are resizing it and you have the resize cursor if you don't put the cursor exactly on the column but move it a bit to the right and then drag it it will reveal the hidden column.  If you want I can make a gid animation of how to resize a 0 column width.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.