RESOLVED: Group By Clicked Column
Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Report Control
Forum Description: Topics Related to Codejock Report Control
URL: http://forum.codejock.com/forum_posts.asp?TID=11349
Printed Date: 20 July 2025 at 3:00am Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com
Topic: RESOLVED: Group By Clicked Column
Posted By: JasonG
Subject: RESOLVED: Group By Clicked Column
Date Posted: 08 July 2008 at 1:45pm
I am looking for some code that will sort AND group the report by the column clicked. When I initialize the form, I am setting a default grouping/sorting as shown here:
Set Column = lstMessages.Columns.Add(3, "From", 130, True) Set C = Column Set Column = lstMessages.Columns.Add(4, "First", 90, True) Set Column = lstMessages.Columns.Add(5, "Last", 90, True) Set Column = lstMessages.Columns.Add(6, "fullmessage", 90, True) lstMessages.GroupsOrder.Add C
The current code I have is below, however the desired affect is not occurring. Only the sorting is taking place... The original grouping is not removed, nor is the new one added.
Private Sub lstMessages_ColumnClick(ByVal Column As XtremeReportControl.IReportColumn) lstMessages.GroupsOrder.DeleteAll lstMessages.GroupsOrder.Add Column lstMessages.Populate End Sub
|
Replies:
Posted By: jpbro
Date Posted: 08 July 2008 at 2:01pm
I have a solution, but it seems a little convoluted, so maybe there's a better way.
It appears the ColumnClick event doesn't fire when you click the header, but the SortOrderChanged event does. Problem is the SortOrderChanged event doesn't tell you what column was clicked, so you have to get the current cursor position, convert it to client coordinates and then get the column from the ReportControl HitTest method:
Private Type POINTAPI x As Long y As Long End Type
Private Declare Function GetCursorPos Lib "user32.dll" (ByRef lpPoint As POINTAPI) As Long Private Declare Function ScreenToClient Lib "user32.dll" (ByVal hwnd As Long, ByRef lpPoint As POINTAPI) As Long
Private Sub ReportControl1_SortOrderChanged() Dim objHT As ReportHitTestInfo Dim udtCursor As POINTAPI
With Me.ReportControl1 GetCursorPos udtCursor ScreenToClient .hwnd, udtCursor Set objHT = .HitTest(udtCursor.x, udtCursor.y) If Not objHT Is Nothing Then If Not objHT.Column Is Nothing Then .GroupsOrder.DeleteAll .GroupsOrder.Add objHT.Column
.Populate End If End If End With End Sub
|
------------- Product: Xtreme SuitePro (ActiveX) version 16.2.6 Platform: Windows XP - SP3
Language: Visual Basic 6.0 SP6
|
Posted By: jpbro
Date Posted: 08 July 2008 at 2:04pm
There is a better solution...You can use the SortOrder object to get the first column in the Sort Order and skip the API & HitTest methods entirely:
Private Sub ReportControl1_SortOrderChanged() With Me.ReportControl1 .GroupsOrder.DeleteAll .GroupsOrder.Add .SortOrder.Column(0) .Populate End With End Sub
|
------------- Product: Xtreme SuitePro (ActiveX) version 16.2.6 Platform: Windows XP - SP3
Language: Visual Basic 6.0 SP6
|
Posted By: JasonG
Date Posted: 08 July 2008 at 2:06pm
|