Link to home
Start Free TrialLog in
Avatar of TheMadManiac
TheMadManiac

asked on

Listview(report mode): hiding but not removing columns

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
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

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
Avatar of TheMadManiac
TheMadManiac

ASKER

That will work :)

Post as answer please.

Tam
ASKER CERTIFIED SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Absolutely.  Here is what you have to do:

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

This will re-size the column.

Anthony
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.