"Sticky" (multiple) selection
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=12832
Printed Date: 21 November 2024 at 12:05pm Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com
Topic: "Sticky" (multiple) selection
Posted By: MNovaro
Subject: "Sticky" (multiple) selection
Date Posted: 01 December 2008 at 8:54am
Hello, everybody
I would like to use a Report Control with a "Sticky" selection, that is: selecting multiple items without having to press CTRL (or Shift). In other words: I would like to select a row on click event if it is not selected, and unselect it if it is selected.
Is this possible??
Thanks in advance for any help Regards Marco
|
Replies:
Posted By: jpbro
Date Posted: 01 December 2008 at 9:32am
Set the MultiSelectMode property to True.
------------- Product: Xtreme SuitePro (ActiveX) version 16.2.6 Platform: Windows XP - SP3
Language: Visual Basic 6.0 SP6
|
Posted By: MNovaro
Date Posted: 02 December 2008 at 3:02am
I guess I have no "MultiSelectMode", since I'm still using the 11.2.1 release.... Is there a way to "simulate" this with code?
Thanks again Marco
|
Posted By: jpbro
Date Posted: 02 December 2008 at 11:28am
You could do this:
Private Sub ReportControl1_FocusChanging(ByVal NewRow As XtremeReportControl.IReportRow, ByVal NewColumn As XtremeReportControl.IReportColumn, ByVal NewItem As XtremeReportControl.IReportRecordItem, Cancel As Boolean) Cancel = True NewRow.Selected = Not NewRow.Selected End Sub
|
The only problem being that the focus (dotted rectangle) doesn't move to the most recently clicked row. Unfortunately, all of my attempts to move the focus also reset the selection to a single item. This may or may not be a problem for you though.
------------- Product: Xtreme SuitePro (ActiveX) version 16.2.6 Platform: Windows XP - SP3
Language: Visual Basic 6.0 SP6
|
Posted By: jpbro
Date Posted: 02 December 2008 at 12:00pm
I just noticed another problem with the above approach - If you click the currently focused row when there are multiple rows selected, the selection will be reset to the just the single focused row. This is because the FocusChanging event doesn't fire (since the focus isn't changing) and we can't cancel the default behaviour. Unfortunately, there is no corresponding SelectionChanging event that would allow us to cancel any selection change. I'll see if I can figure out a workaround.
------------- Product: Xtreme SuitePro (ActiveX) version 16.2.6 Platform: Windows XP - SP3
Language: Visual Basic 6.0 SP6
|
Posted By: MNovaro
Date Posted: 02 December 2008 at 12:06pm
Hello, jbpro
thanks for your help: I can't test your solution in here, but I will do asap and I'll let you know....
|
Posted By: MNovaro
Date Posted: 03 December 2008 at 4:11am
Ehm... I neither have a "FocusChanging" event in my version...
|
Posted By: jpbro
Date Posted: 03 December 2008 at 7:59pm
Hi MNovaro,
Sorry, I didn't know that event wasn't available in 11.2.1. Also, sorry for taking a while to get back, I've been busy with work and a new baby girl!
Anyway, I think I have found a solution for you. Assuming you have the MouseDown and MouseUp events, this should work:
Option Explicit
Private mo_SelectedRows As Collection
Private Sub Form_Load() ' Save the starting selection (usually the first row only). ' If your code selects other rows at startup programmatically, ' then call RememberSelection after you have made the selection in code RememberSelection ' Call this after you have populated your ReportControl and if you change the selection programmatically End Sub
Private Sub ReportControl1_MouseDown(Button As Integer, Shift As Integer, x As Long, y As Long) Dim lo_Hit As ReportHitTestInfo Dim lo_Row As ReportRow ' Determine if the mouse is over a selectable row Set lo_Hit = Me.ReportControl1.HitTest(x, y) If Not lo_Hit Is Nothing Then If Not lo_Hit.Row Is Nothing Then ' The mouse is over a selectable row ' Restore the previous selection since the MouseDown will ' reset the selection to a single (hovered over) item RestoreSelection ' Check to see if the current row was selected last time ' we saved the selection. If it was selected, then we ' should de-select it this click For Each lo_Row In mo_SelectedRows If lo_Row Is lo_Hit.Row Then ' Row was previously selected, so de-select it lo_Hit.Row.Selected = False Exit For End If Next lo_Row ' Save the current selection state RememberSelection End If End If End Sub
Private Sub ReportControl1_MouseUp(Button As Integer, Shift As Integer, x As Long, y As Long) ' Mouse-up will reset the selection, so we should restore our previous selection if required Dim lo_Hit As ReportHitTestInfo ' Determine if mouse is over a selectable row Set lo_Hit = Me.ReportControl1.HitTest(x, y) If Not lo_Hit Is Nothing Then If Not lo_Hit.Row Is Nothing Then ' We are over a row ' Remove the currently selected item Me.ReportControl1.SelectedRows.DeleteAll ' Restore the saved selection from MouseDown RestoreSelection End If End If End Sub
Private Sub RememberSelection() ' Save the current state of selected rows Dim lo_Row As ReportRow Set mo_SelectedRows = New Collection For Each lo_Row In Me.ReportControl1.SelectedRows mo_SelectedRows.Add lo_Row Next lo_Row End Sub
Private Sub RestoreSelection() ' Restore the selection state saved in RememberSelection() Dim lo_Row As ReportRow For Each lo_Row In mo_SelectedRows lo_Row.Selected = True Next lo_Row End Sub
|
If you don't have these events, then the best I can suggest is to buy the upgrade ;)
------------- Product: Xtreme SuitePro (ActiveX) version 16.2.6 Platform: Windows XP - SP3
Language: Visual Basic 6.0 SP6
|
Posted By: MNovaro
Date Posted: 10 December 2008 at 5:07am
Wow!!
Thanks, jbpro: this actually works as I expected!!
Thank you really very much for the help Marco
|
Posted By: jpbro
Date Posted: 10 December 2008 at 10:30am
Glad to help, Marco!
------------- Product: Xtreme SuitePro (ActiveX) version 16.2.6 Platform: Windows XP - SP3
Language: Visual Basic 6.0 SP6
|
|