Link to home
Start Free TrialLog in
Avatar of PantoffelSlippers
PantoffelSlippersFlag for South Africa

asked on

Using groups in the listview control

Hi Experts,

I'm writing a VB.Net 2005 application.  I have a tree-view control on my form and a listview control on its right.  The listview control has to show all the child nodes of the selected treeview node. That's easy enough, however I'm having some problems formatting the listview control the way I want it.

I'd like to use that lovely group heading (the one with the fading blue line, looks very cool).  In order to use groups, I think the listview's view must be set to details which I've done.  The heading is displayed.

I've got two problems remaining:

1. The group heading reads "Default".  How do I change it?  I've tried this without luck:
           me.lvwNodeContent.Groups(0).Name = ParentNode.Text

2. I don;t want the listview's column header displayed.  It looks ugly!! Any way of hiding it?


Thanks
Avatar of SteveH_UK
SteveH_UK
Flag of United Kingdom of Great Britain and Northern Ireland image

You need to use the Groups and ShowGroups properties.  I don't think you need to use the Details view.

Your items should be added to the groups, rather than directly to the ListView.
ASKER CERTIFIED SOLUTION
Avatar of SteveH_UK
SteveH_UK
Flag of United Kingdom of Great Britain and Northern Ireland 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
Add, I was wrong.  You do add the items to the ListView directly, but you also set the item's Group property.  Mentioned in the how-to.  Don't forget the Application.EnableVisualStyles method call, either.
SOLUTION
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia 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
SOLUTION
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
SOLUTION
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
Avatar of PantoffelSlippers

ASKER

Thanks Experts!

Let me have a look!
Thank you experts!
A perfect solution in no time.
Thanks for effort - everyone joined in.
Thanks again!
My final code looks like this:

  Private Sub UpdateContent(ByRef ParentNode As TreeNode)
    Dim XNode As TreeNode
    Dim XItem As ListViewItem


    'Prepare the listview
    With Me.lvwNodeContent
      .Items.Clear()
      .Groups.Clear()
      .Columns.Clear()

      .Columns.Add("", CInt(lvwNodeContent.Width * 0.98), HorizontalAlignment.Left)
      .Groups.Add(ParentNode.Text, ParentNode.Text)
    End With


    'Add the nodes
    For Each XNode In ParentNode.Nodes
      XItem = lvwNodeContent.Items.Add(XNode.Text)
      XItem.Tag = XNode.Index
      XItem.ImageIndex = XNode.ImageIndex
      XItem.Group = lvwNodeContent.Groups(ParentNode.Text)  'Key
    Next

  End Sub
Thank you experts
You're welcome :)