Listview Groups Addition

How to add Groups in Listview

Page 1 of 1

3 Replies - 29204 Views - Last Post: 14 May 2009 - 09:50 AM Rate Topic: -----

#1 kasbaba  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 134
  • Joined: 03-November 08

Listview Groups Addition

Posted 08 November 2008 - 12:32 PM


I am back with a new question.

I am working on a Listview Control.

I need to show groups in it and am failing to understand which part of my code is incorrect :

'Clear Listview

Dim itm As ListViewItem
Dim GRP As New ListViewGroup
Dim cnt As Long


SqlComm1 = New OleDb.OleDbCommand

 'proceed to Make Groups...find out what we need
SqlComm = CON.CreateCommand
Rs = SqlComm.ExecuteReader
While Rs.Read = True
ForumLSTView.Groups.Add(New ListViewGroup(Rs(0), HorizontalAlignment.Left))
End While

'Now, fill the listview control with all items from the database
'also assign items to the ForumLSTView.Groups

SqlComm = CON.CreateCommand
SqlComm.CommandText = "SELECT * from LOUNGE_TALK order By POSTEDAT DESC"

Rs = SqlComm.ExecuteReader

While Rs.Read = True
cnt = 0
itm = ForumLSTView.Items.Add(CDate(Rs("PostedAt")))

'Get all count of all replies to this post

SqlComm1 = CON.CreateCommand
SqlComm1.CommandText = "SELECT * from LOUNGE_TALK where InReplyto='" & Rs("POSTID") & "'"
Rs1 = SqlComm1.ExecuteReader

While Rs1.Read = True
cnt = cnt + 1
End While


'Now make a group

For i = 0 To ForumLSTView.Groups.Count - 1
If Rs("MNTH") = ForumLSTView.Groups(i).ToString Then					 itm.Group = ForumLSTView.Groups(i)
End If
Next i
itm.Group.Header = Rs("MNTH")
End While

I find nothing wrong as far as the code is concerned, however i was wondering whether there is any setting for the control itself.


A snapshot of the database and field types is attached....
Attached File  db.bmp (290.68K)
Number of downloads: 657

Is This A Good Question/Topic? 0
  • +

Replies To: Listview Groups Addition

#2 Pwn  Icon User is offline

  • D.I.C Regular

Reputation: 19
  • View blog
  • Posts: 458
  • Joined: 25-November 07

Re: Listview Groups Addition

Posted 08 November 2008 - 02:12 PM

Groups can only be shown in certain views, and IIRC it is only in the small and large icon views, but you may want to read up on it to be sure.
Was This Post Helpful? 0
  • +
  • -

#3 kasbaba  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 134
  • Joined: 03-November 08

Re: Listview Groups Addition

Posted 13 December 2008 - 11:30 AM

View Postkasbaba, on 8 Nov, 2008 - 11:32 AM, said:

I need to show groups in it


I have tried many snippets and suggestions, to make Groups, but nothing seems to work.
All I get is a listview control filled with invisible items, no header, no groups.

By re-opening this post I am trying to get some more help.

I am listing a couple of websites that I have tried so far.

1. Experts Exchange
2. Microsoft MSDN

I am curious to know what properties do I set for the Listview control to enable Group view.

Was This Post Helpful? 0
  • +
  • -

#4 JaPitbull  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 14-May 09

Re: Listview Groups Addition

Posted 14 May 2009 - 09:50 AM

It seems i might be a little too late to help, but I've only just joined this web site today. However, I have been able to do that which seems to be puzzling you.

The code below is an extract from one of my projects @ work with some minor changes. I really hope it helps.

N.B. that I am using VS.Net 2008 and the code does not include things that happened in the designer code behind file

Public Class form1

Private WithEvents ColumnHeader_GrpNo As System.Windows.Forms.ColumnHeader
Private WithEvents ColumnHeader_GrpName As System.Windows.Forms.ColumnHeader
Private WithEvents ColumnHeader_AmtRenewals As System.Windows.Forms.ColumnHeader
Private WithEvents ColumnHeader_DateCreated As System.Windows.Forms.ColumnHeader

Private dataTable As dsStats
Private dr As dsStatsTableAdapters.stdRenewStatsTableAdapter
Private dr2 As dsStatsTableAdapters.ageBandStatsTableAdapter

Private Sub addData(ByVal grpNo As String, ByVal name As String, ByVal amount As Int32, ByVal datecreated As String, Optional ByVal grpName As String = "Default")
Dim lvi As ListViewItem
Dim aHeaders(3) As String

aHeaders(0) = grpNo
aHeaders(1) = name
aHeaders(2) = amount.ToString
aHeaders(3) = datecreated

lvi = New ListViewItem(aHeaders)

End Sub

Private Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

'Create two groups
Dim ListViewGroup1 As System.Windows.Forms.ListViewGroup = New System.Windows.Forms.ListViewGroup("Regular", System.Windows.Forms.HorizontalAlignment.Left)
Dim ListViewGroup2 As System.Windows.Forms.ListViewGroup = New System.Windows.Forms.ListViewGroup("Age Band Movement", System.Windows.Forms.HorizontalAlignment.Left)

'Create the List View columns in memory

ColumnHeader_GrpNo = New System.Windows.Forms.ColumnHeader
ColumnHeader_GrpNo.Text = "Group Number"

ColumnHeader_GrpName = New System.Windows.Forms.ColumnHeader
ColumnHeader_GrpName.Text = "Client Name"

ColumnHeader_AmtRenewals = New System.Windows.Forms.ColumnHeader
ColumnHeader_AmtRenewals.Text = "# of Renewals"
ColumnHeader_AmtRenewals.TextAlign = System.Windows.Forms.HorizontalAlignment.Center

ColumnHeader_DateCreated = New System.Windows.Forms.ColumnHeader
ColumnHeader_DateCreated.Text = "Date Created"

With ListView1
.CheckBoxes = True
.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {ColumnHeader_GrpNo, ColumnHeader_GrpName, ColumnHeader_AmtRenewals, ColumnHeader_DateCreated})
.FullRowSelect = True
.GridLines = True
.View = System.Windows.Forms.View.Details


ListViewGroup1.Header = "Regular"
ListViewGroup1.Name = "ListViewGroup_Regular"

ListViewGroup2.Header = "Age Band Movement"
ListViewGroup2.Name = "ListViewGroup_AgeBand"

'Instance a new data table in memory
dataTable = New dsStats

dr = New dsStatsTableAdapters.stdRenewStatsTableAdapter

For Each row As dsStats.stdRenewStatsRow In dataTable.stdRenewStats
addData(CStr(row(0)), CStr(row(1)), CInt(row(2)), CStr(row(3)), "ListViewGroup_Regular")

dr2 = New dsStatsTableAdapters.ageBandStatsTableAdapter

For Each row As dsStats.ageBandStatsRow In dataTable.ageBandStats
addData(CStr(row(0)), CStr(row(1)), CInt(row(2)), CStr(row(3)), "ListViewGroup_AgeBand")

End Sub
End Class
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1