StrataFrame Forum

How to use the ListView Grouping?

http://forum.strataframe.net/Topic16899.aspx

By Edhy Rijo - 6/7/2008

Hi Trent,

I saw this listview from one of your videos and now I have the need to incorporate this grouping feature in one of my listview.

I looked in the forum and the help file and could not find any info about how to do this.  Could you please post some sample code on how to accomplish this grouping display in the listview?

By Ivan George Borges - 6/9/2008

Hey Edhy.

Just to get you going, use your ListView RowPopulating Event to set e.UseGroup to True. Then you set the e.GroupHeaderText to the Group you want and it should work. Something like:

    Private Sub MyListView_RowPopulating(ByVal e As MicroFour.StrataFrame.UI.Windows.Forms.RowPopulatingEventArgs) _
      Handles MyListView.RowPopulating

        With CType(e.BusinessObject, MyBO)
            '-- Set Columns
            e.Values(0).DisplayValue = Something
            e.Values(1).DisplayValue = SomethingElse

            e.UseGroup = True

            Select Case .myField
                Case SomeCondition1
                    e.GroupHeaderText = "Group1"

                    '-- here you can even set an image, for example from a ImageListControl
                    e.ImageIndex = 1

                Case SomeCondition2
                    e.GroupHeaderText = "Group2"
                    e.ImageIndex = 2

                Case SomeCondition3
                    e.GroupHeaderText = "Group3"
                    e.ImageIndex = 3

                Case SomeCondition4
                    e.GroupHeaderText = "Group4"
                    e.ImageIndex = 4

                Case Else
                    e.GroupHeaderText = "Not Defined"
                    e.ImageIndex = 5
            End Select

        End With
    End Sub

By Edhy Rijo - 6/9/2008

Hi Ivan,

Thanks, that will get me going, will try now.
By Edhy Rijo - 6/9/2008

Ok, I have the group showing, but since this method is executing per row, how do I filter the rows to show in the correct group? so the records for group 1 will be show under group 1 and the records for group 2 will be shown in group 2 and so on.
By Ivan George Borges - 6/9/2008

Have you tried sorting the contents of your BO on the column you are using for grouping?
By Trent L. Taylor - 6/9/2008

I don't understand your question, but the the rows are grouped based on the GroupHeaderText.  When you set the e.GroupHeaderText value, any row that has the same text will appear in the same group.  That is it...not anything more to it.  Also, if you eve set the e.UseGroup to False, this gets set for the entire grid, not a per item basis.  But it still needs to be set within this method in order to take action.

So if you are trying to sort, you could include this as part of a BO sort or part of a query sort.  Hope that makes sense.

By Edhy Rijo - 6/9/2008

Trent L. Taylor (06/09/2008)
When you set the e.GroupHeaderText value, any row that has the same text will appear in the same group. That is it...not anything more to it.

So if you are trying to sort, you could include this as part of a BO sort or part of a query sort. Hope that makes sense.




Trent, Ivan,

That was it, having the proper ORDER BY in the fill method of the BO and just setting the GroupHeaderText to a value that is part of the row will do the trick. This is my code:



Private Sub lvPaymentSchedule_RowPopulating(ByVal e As MicroFour.StrataFrame.UI.Windows.Forms.RowPopulatingEventArgs) Handles lvPaymentSchedule.RowPopulating

Dim loBO As PaymentScheduleBO

loBO = e.BusinessObject

e.UseGroup = True

e.GroupHeaderText = "Vehicle Group " & loBO.FK_Vehicle.ToString

End Sub





Thanks you both! Smile
By Ivan George Borges - 6/9/2008

Glad it helped, Edhy. Wink
By Edhy Rijo - 6/9/2008

One more thing, is there a way to add an image to the GroupHeader only?
By Trent L. Taylor - 6/10/2008

Nope, sorry. Ermm