ReportView Row Selections

Started by chrislegarth, December 11, 2022, 07:31:36 AM

Previous topic - Next topic

chrislegarth

I realize this ReportView event option is called @deRvrSelectItem Select Row: User has selected row in the REPORTVIEW control.
This appears to work as described so my post is probably not a bug but rather a request.

What I am trying to do is allow my users to select multiple rows in a ReportView and sum a column in that selection.
This works if they select a new row but does not update when a previously selected row is "deselected".  It appears that @deRvrSelect does not fire on a deselection.

Is there another way to accomplish this without using the @deRviCheck event option which I have not yet tried though suspect would work since it supports unchecking an item?

Thanks!!!

td

The underlying Windows Common Control does not support a "de-activation" notification message so WIL dialogs do not either. You could create a count of selected items and then periodically check if that count has changed using a "timer" event. If it has changed then fetch the selected and recalculate your sum.

The request will be added to the user-requested improvements list but for now, here is a quick and dirty example that illustrates one approach. Note that there may be other methods that may be more efficient:

Code (winbatch) Select
;***************************************************************************
;** RV_GetSelectedCount
;**
;** Purpose: Get count of report view selected items.
;** Input:  _hWnd - window handle to report view control.
;** Output: Count of selected items.
;**
;** Notes: Created as a subroutine to improve performance.
;***************************************************************************
#definesubroutine RV_GetSelectedCount(_hWnd)
   ; LVM_FIRST               4096
   ;LVM_GETSELECTEDCOUNT = LVM_FIRST + 50 = 4146
   return DllCall("user32.dll", long:"SendMessageW",long:_hWnd,long:4146,long:0,long:0)
#endsubroutine

;; Dialog UDS
#DefineSubroutine TestUDP(_hDlg,_Event,_Name,_EventInfo,_ChangeInfo)
   switch _Event                                   
      case @deInit                                         
         DialogProcOptions(_hDlg,@deTimer,500)
         DialogProcOptions(_hDlg,@deRvrSelect,@TRUE)
         return(@retDefault)

      case @dePbPush
         if _Name == "PushButton_OK"               ; OK
            return(@retDefault)

         elseif _Name == "PushButton_Cancel"       ; Cancel
            return(@retDefault)

         endif                                           
         return(@retDefault)

      case @deTimer
          hRv = DialogControlGet(_hDlg, "ReportView", @dchWnd,0)
          nCurrent = RV_GetSelectedCount(hRv)
          nPrev = DialogControlGet(_hDlg, "Count", @dcTitle,0)
          if nPrev != nCurrent
            DialogControlSet(_hDlg, "Count",@dcTitle, nCurrent)
          endif
          return(@retDefault)                                     

      case @deRvrSelect                                    ; ID "ReportView"  rvControl
          hRv = DialogControlGet(_hDlg, "ReportView", @dchWnd,0)
          nCurrent = RV_GetSelectedCount(hRv)
          DialogControlSet(_hDlg, "Count",@dcTitle, nCurrent)
          return(@retDefault)

      case @deClose                                        ; System menu close event
         return(@retDefault)

   endswitch                                               
   return(@retDefault)
#EndSubroutine                                             

; The WIL Dialog.
RvSelCntFormat=`WWWDLGED,6.2`

RvSelCntCaption=`RV Selection Example`
RvSelCntX=341
RvSelCntY=220
RvSelCntWidth=668
RvSelCntHeight=379
RvSelCntNumControls=005
RvSelCntProcedure=`TestUDP`
RvSelCntFont=`DEFAULT`
RvSelCntTextColor=`DEFAULT`
RvSelCntBackground=`DEFAULT,DEFAULT`
RvSelCntConfig=0
RvSelCntDPI=`216,10,20`

RvSelCnt001=`178,338,058,019,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,@csDefButton,DEFAULT,DEFAULT,DEFAULT`
RvSelCnt002=`372,338,057,019,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
RvSelCnt003=`060,020,523,220,REPORTVIEW,"ReportView",rvControl,DEFAULT,DEFAULT,30,@csFullSel,DEFAULT,DEFAULT,DEFAULT`
RvSelCnt004=`257,257,079,014,STATICTEXT,"Label",DEFAULT,"Selection Count:",DEFAULT,40,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
RvSelCnt005=`356,258,086,016,STATICTEXT,"Count",DEFAULT,"0",DEFAULT,50,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("RvSelCnt")

:cancel
exit
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

Another lame example that actually sums selected rows.

Code (winbatch) Select
;***************************************************************************
;** SumSelected
;**
;** Purpose: Sums the first row of all selected items in a report view
;**          control
;** Input: _hDlg - dialog handle.
;**        _CltName - name of reportview control with numbers in first column
;** Output: Sum of selected items in first column of control.
;**
;** Notes: Created as a subroutine to improve performance.
;***************************************************************************
#definesubroutine SumSelected(_hDlg, _CtlName)
   Sum = 0
   aSelected = DialogControlGet(_hDlg, _CtlName, @dcSelect,0)
   foreach Item in aSelected
      Sum += Item
   next
   return Sum
#endsubroutine

; Number of currently select items.
NumSelected = 0

; Faux data used for testing.
For i = 0 to 9
   Data[i] = i+1
next

;; Dialog's UDS
#DefineSubroutine TestUDP(_hDlg,_Event,_Name,_EventInfo,_ChangeInfo)
   switch _Event                                   
      case @deInit                                         
         DialogProcOptions(_hDlg,@deTimer,250)
         DialogProcOptions(_hDlg,@deRvrSelect,@TRUE)
         return(@retDefault)

      case @dePbPush
         if _Name == "PushButton_OK"               ; OK
            return(@retDefault)

         elseif _Name == "PushButton_Cancel"       ; Cancel
            return(@retDefault)

         endif                                           
         return(@retDefault)

      case @deTimer
          hRv = DialogControlGet(_hDlg, "ReportView", @dchWnd,0)
          ; LVM_FIRST               4096
          ; LVM_GETSELECTEDCOUNT = LVM_FIRST + 50 = 4146
          Current = DllCall("user32.dll", long:"SendMessageW",long:hRv ,long:4146,long:0,long:0)         
          if NumSelected != Current
            NumSelected = Current
            Sum = SumSelected(_hDlg, "ReportView")
            DialogControlSet(_hDlg, "Total",@dcTitle, Sum)
          endif
          return(@retDefault)                                     

      case @deRvrSelect                                    ; ID "ReportView" 
          Sum = SumSelected(_hDlg, "ReportView")
          NumSelected = ArrInfo(aSelected, 1)
          DialogControlSet(_hDlg, "Total",@dcTitle, Sum)
          return(@retDefault)

      case @deClose                                     
         return(@retDefault)

   endswitch                                               
   return(@retDefault)
#EndSubroutine                                             

; The WIL Dialog.
RvSelCntFormat=`WWWDLGED,6.2`

RvSelCntCaption=`RV Selection Example`
RvSelCntX=341
RvSelCntY=220
RvSelCntWidth=668
RvSelCntHeight=379
RvSelCntNumControls=005
RvSelCntProcedure=`TestUDP`
RvSelCntFont=`DEFAULT`
RvSelCntTextColor=`DEFAULT`
RvSelCntBackground=`DEFAULT,DEFAULT`
RvSelCntConfig=0
RvSelCntDPI=`216,10,20`

RvSelCnt001=`178,338,058,019,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,@csDefButton,DEFAULT,DEFAULT,DEFAULT`
RvSelCnt002=`372,338,057,019,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
RvSelCnt003=`060,020,523,220,REPORTVIEW,"ReportView",Data,DEFAULT,DEFAULT,30,@csFullSel,DEFAULT,DEFAULT,DEFAULT`
RvSelCnt004=`257,257,079,014,STATICTEXT,"Label",DEFAULT,"Selection total:",DEFAULT,40,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
RvSelCnt005=`356,258,086,016,STATICTEXT,"Total",DEFAULT,"0",DEFAULT,50,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("RvSelCnt")

:cancel
exit

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

chrislegarth

Thanks Tony for the examples and going above and beyond to help!