Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. ListView add and group items

ListView add and group items

Scheduled Pinned Locked Moved Visual Basic
question
11 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    svh1985
    wrote on last edited by
    #1

    How do i add items and group them in a ListView? Im using this to add a new item: ListView1.Items.Add("ITEM1", 0) And this for making a Group: ListView1.Groups.Add(0, "Group1") But how do I make "ITEM1" part of the group "Group1" THX

    L 1 Reply Last reply
    0
    • S svh1985

      How do i add items and group them in a ListView? Im using this to add a new item: ListView1.Items.Add("ITEM1", 0) And this for making a Group: ListView1.Groups.Add(0, "Group1") But how do I make "ITEM1" part of the group "Group1" THX

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Looks like this article may have what you are looking for: ListView Grouping XP Style

      S 1 Reply Last reply
      0
      • L Lost User

        Looks like this article may have what you are looking for: ListView Grouping XP Style

        S Offline
        S Offline
        svh1985
        wrote on last edited by
        #3

        thanks for your reply i downloaded the project it is in c# so im not sure if i understand it all, but i give it a try

        L 1 Reply Last reply
        0
        • S svh1985

          thanks for your reply i downloaded the project it is in c# so im not sure if i understand it all, but i give it a try

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Why not use the XPListView user control "as is" in your project? Just add the user control to your project and use it instead of the standard listview control. The XPListView control has two properties that makes grouping automatic ... AutoGroupMode and AutoGroupColumn.

          S 1 Reply Last reply
          0
          • L Lost User

            Why not use the XPListView user control "as is" in your project? Just add the user control to your project and use it instead of the standard listview control. The XPListView control has two properties that makes grouping automatic ... AutoGroupMode and AutoGroupColumn.

            S Offline
            S Offline
            svh1985
            wrote on last edited by
            #5

            again thx for your reply. my project is build in vb.net 2005 and if i build the xplistview in vs.net 2005 i get lots of errors witch i don't know how to solve becouse i have no knowledge of c# is it impossible to group items in the listview at runtime?

            T L 2 Replies Last reply
            0
            • S svh1985

              again thx for your reply. my project is build in vb.net 2005 and if i build the xplistview in vs.net 2005 i get lots of errors witch i don't know how to solve becouse i have no knowledge of c# is it impossible to group items in the listview at runtime?

              T Offline
              T Offline
              TwoFaced
              wrote on last edited by
              #6

              Yup, here is a simple example.

              Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                  ' Add a column to the listview
                  ListView1.Columns.Add("Name")
              
                  ' Create two groups
                  ListView1.Groups.Add("Group1", "Group1")
                  ListView1.Groups.Add("Group2", "Group2")
              
                  ' Add two items and assign them to the desired group
                  ListView1.Items.Add("Test Group1").Group = ListView1.Groups("Group1")
                  ListView1.Items.Add("Test Group2").Group = ListView1.Groups("Group2")
              
                  ' Add another item differently and give it a group
                  ListView1.Items.Add(New ListViewItem("Test Group1 again", ListView1.Groups("Group1")))
              
                  ListView1.View = View.Details
              
                  ' Basically you need to know that the groups collection is where you 
                  ' add groups to the listview
              
                  ' I've showed two different ways you can add an item and assign it to a group
                  ' This should give you an idea how to work with groups
              End Sub
              
              S 1 Reply Last reply
              0
              • T TwoFaced

                Yup, here is a simple example.

                Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                    ' Add a column to the listview
                    ListView1.Columns.Add("Name")
                
                    ' Create two groups
                    ListView1.Groups.Add("Group1", "Group1")
                    ListView1.Groups.Add("Group2", "Group2")
                
                    ' Add two items and assign them to the desired group
                    ListView1.Items.Add("Test Group1").Group = ListView1.Groups("Group1")
                    ListView1.Items.Add("Test Group2").Group = ListView1.Groups("Group2")
                
                    ' Add another item differently and give it a group
                    ListView1.Items.Add(New ListViewItem("Test Group1 again", ListView1.Groups("Group1")))
                
                    ListView1.View = View.Details
                
                    ' Basically you need to know that the groups collection is where you 
                    ' add groups to the listview
                
                    ' I've showed two different ways you can add an item and assign it to a group
                    ' This should give you an idea how to work with groups
                End Sub
                
                S Offline
                S Offline
                svh1985
                wrote on last edited by
                #7

                thanks it works perfect!

                S 1 Reply Last reply
                0
                • S svh1985

                  again thx for your reply. my project is build in vb.net 2005 and if i build the xplistview in vs.net 2005 i get lots of errors witch i don't know how to solve becouse i have no knowledge of c# is it impossible to group items in the listview at runtime?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  That's interesting. I downloaded and then opened the XPListView solution in VS 2005 and the project was successfully converted from 2003 to 2005. Then I built the user control using VS 2005. There were no errors either in the conversion or the build. I added the re-built XPListView DLL to the VS 2005 Toolbox and then pasted the XPListView control onto a form in a test project. It works great and I now have the extended listview available for all of my projects.

                  S 1 Reply Last reply
                  0
                  • L Lost User

                    That's interesting. I downloaded and then opened the XPListView solution in VS 2005 and the project was successfully converted from 2003 to 2005. Then I built the user control using VS 2005. There were no errors either in the conversion or the build. I added the re-built XPListView DLL to the VS 2005 Toolbox and then pasted the XPListView control onto a form in a test project. It works great and I now have the extended listview available for all of my projects.

                    S Offline
                    S Offline
                    svh1985
                    wrote on last edited by
                    #9

                    can you email me your (converted) project? and the dll? i dont understand why i got so many errors, i cant even open the form designer becouse of all the errors. ive removed the AT for spam reasons. svanheest gmail.com thanks!!

                    L 1 Reply Last reply
                    0
                    • S svh1985

                      can you email me your (converted) project? and the dll? i dont understand why i got so many errors, i cant even open the form designer becouse of all the errors. ive removed the AT for spam reasons. svanheest gmail.com thanks!!

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      Just letting you know that I emailed the converted XPListView DLL via an off-board email. If you don't receive it, let me know and I'll set up a download location.

                      1 Reply Last reply
                      0
                      • S svh1985

                        thanks it works perfect!

                        S Offline
                        S Offline
                        svh1985
                        wrote on last edited by
                        #11

                        Do you also know how to sort the items by the group name? now when i add a group it will show the groups in the order ive added them thanks!

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups