XBROWSE CheckBOX SelectALL

XBROWSE CheckBOX SelectALL

Postby shri_fwh » Sat Mar 30, 2019 5:46 am

Dear Rao Sir ,

I have tried to use CheckBox in XBROWSE and its working checks and un-checks BUT it is NOT working for SelectAll method.

The Code is given below. Could you please guide me

Code: Select all  Expand view


#include "fivewin.ch"

function Main

   local oDlg, oBrw, aData
   local oCn := FW_DemoDB( 1 )
   local oRs

   oRs := oCn:RowSet( "select * from clients" )


   DEFINE DIALOG oDlg SIZE 400,400 PIXEL TRUEPIXEL

   @ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oRs  ;
      COLUMNS "Code", "First", "Last" ;
      LINES NOBORDER




    WITH OBJECT oBrw:InsCol( 1 )

      :cHeader       := " "
      :bEditValue    := { || If( AScan( oBrw:aSelected, oBrw:BookMark ) > 0, .t., nil ) }
      :SetCheck()
      :nHeadBmpNo    := { || If( Len( oBrw:aSelected ) == oBrw:nLen, 1, 2 ) }
      :bLClickHeader := < |r,c,f,oCol|



                            If  Len( oBrw:aSelected ) == oBrw:nLen
                                oBrw:SelectNone()
                            else
                                oBrw:SelectAll()
                                ?"Select All"
                            endif


                            return nil
                        >

   END


   WITH OBJECT oBrw
      :nMarqueeStyle    := MARQSTYLE_HIGHLROW
      :lMultiSelect     := .f.
      :bClrSelFocus     := { || { CLR_BLACK, CLR_HGRAY } }
      :nStretchCol      := 3
      :aCols[ 1 ]:bClrSelFocus := { ||{  CLR_BLACK, CLR_WHITE } }
      :bLClicked        := { |r,c,f,oBrw| If( oBrw:MouseColPos( c ) == 1 , ;
                           If( ( f := AScan( oBrw:aSelected, oBrw:BookMark ) ) == 0, ;
                           AAdd( oBrw:aSelected, oBrw:BookMark ), ;
                           ADel( oBrw:aSelected, f, .t. ) ), nil ), ;
                           oBrw:RefreshCurrent() }
      :CreateFromCode()
   END




   ACTIVATE DIALOG oDlg CENTERED

return nil

 


Thanks
Shridhar
Thanks
Shridhar
FWH 19.12, BCC 7 32 bit, MariaDB
shri_fwh
 
Posts: 301
Joined: Mon Dec 07, 2009 2:49 pm

Re: XBROWSE CheckBOX SelectALL

Postby nageswaragunupudi » Wed Apr 03, 2019 12:46 pm

We recommend this approach for users with recent versions of FWH
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local oCn, oRs
   local oDlg, oBrw, oFont

   oCn   := FW_DemoDB()
   oRs   := oCn:Customer

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 700,600 PIXEL TRUEPIXEL FONT oFont

   @ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oRs ;
      COLUMNS  {|| oBrw:IsSelectedRow() }, "FIRST", "CITY", "SALARY" ;
      HEADERS  " " ;
      COLSIZES "9999" ;
      CELL LINES FOOTERS NOBORDER

   WITH OBJECT oBrw
      WITH OBJECT :aCols[ 1 ]
         :SetCheck()
         :bFooter       := { || Len( oBrw:aSelected ) }
         :nHeadBmpNo    := { || If( Len( oBrw:aSelected ) == oBrw:nLen, 1, 2 ) }
         :bLClickHeader := { || oBrw:SelectRow( If( Len( oBrw:aSelected ) < oBrw:nLen, 4, 0 ) ), ;
                                oBrw:Refresh() }
      END
      WITH OBJECT :Salary
         :nFooterType   := AGGR_SUM
         :bSumCondition := { || oBrw:IsSelectedRow() }
      END
      :bLDblClick := { || oBrw:SelectRow() }
      :bKeyChar   := { |k| If( k == 32, ( oBrw:SelectRow(), 0 ), nil ) }
      :bClrStd    := { || { CLR_BLACK, If( oBrw:IsSelectedRow(), CLR_HGREEN, CLR_WHITE ) } }
      //
      :MakeTotals()
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

   oRs:Close()
   oCn:Close()

return nil
 


I have provided to toggle selection with double click and pressing space key. You can change it as you like.
Generally try to avoid toggling on single click, because single click is meant for repositioning the row,

This sample also demonstrates automatic recalculation of footers and refreshing without any extra code. Please also note that the sum of salary column is a conditional sum of selected rows only.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: XBROWSE CheckBOX SelectALL

Postby shri_fwh » Sun Apr 07, 2019 6:04 am

Dear Sir ,

Many thanks for this example and providing tips on the conditional sum.

Thanks
Shridhar
Thanks
Shridhar
FWH 19.12, BCC 7 32 bit, MariaDB
shri_fwh
 
Posts: 301
Joined: Mon Dec 07, 2009 2:49 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Silvio.Falconi and 97 guests