Page 1 of 2

FWH 2102: XBrowse:SetMultiSelectCol()

Posted: Sat Mar 13, 2021 7:40 pm
by nageswaragunupudi
Recently many programmers are preferring to provide multiple selection of rows, by showing the selection by way of checkboxes in a separate column (mostly the first column), in preference to the older way of selecting Marquee style MARQSTYLE_HIGHLROWMS.

However, this requires quite a bit of extra coding by the programmer. Now this is very much simplified.

What all required is to make one call to the new Method SetMultiSelectCol().

Syntax:

Code: Select all | Expand

oBrw:SetMultiSelectCol( [uCol], [lFooter] )


Parameters:
1. [uCol]: Optional. If the method is called without parameters or uCol as nil, xbrowse inserts a new column in the 1st position before all defined columns and makes this is the multiselect column.
If uCol is specified (as column object or column's header/creation ordr), that column is configured as multiselection column.

2. [lFooter]: Optional. Defaults to oBrw:lFooter. If .t., sets footer of the column to display the number of records selected.

This column is available as oBrw:oMultiSelCol.

Toggling selection:
1. Double click of space key in this column toggles selection.
2. When oBrw:lFastEdit is .F., space key always toggles selection.
3. If oBrw:bLDblClick is nil, double click on any column toggles selection, if that column's bLDClickdata also is nil.
4. Ctrl-Click always toggles selection.
5. Shift-Click selects all rows from the last selected row till the current row.

Footers:
If any footers contain conditional aggregates depending on the selected rows, such aggregates are automatically updated in the most optimal way, without any extra code by the programmer.

Here is a sample:

Code: Select all | Expand


#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local oDlg, oFont, oBrw

   FWNumFormat( "A", .t. )

   USE CUSTOMER NEW VIA "DBFCDX"

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 750,500 PIXEL TRUEPIXEL FONT oFont ;
      TITLE FWVERSION + " : oBrw:SetMultiSelectCol()"

   @ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE ALIAS() ;
      COLUMNS "FIRST", "CITY", "AGE", "SALARY" ;
      CELL LINES NOBORDER FOOTERS

   WITH OBJECT oBrw
      :RecSelShowRecNo()
      :bClrStd          := { || { CLR_BLACK, If( oBrw:SelectRow(), 0x88EDFB, CLR_WHITE ) } }
      //
      :Salary:nFooterType := AGGR_SUM
      :Salary:bSumCondition := { || oBrw:SelectRow() }
      :Age:nFooterType := AGGR_AVG
      :Age:bSumCondition := { || oBrw:SelectRow() }
      //
      :SetMultiSelectCol()
      :MakeTotals()
      //
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil
 


Image

Re: FWH 2102: XBrowse:SetMultiSelectCol()

Posted: Mon Mar 15, 2021 11:42 am
by Silvio.Falconi
nice

Re: FWH 2102: XBrowse:SetMultiSelectCol()

Posted: Mon Mar 15, 2021 10:02 pm
by Ariel
Mr.Rao,

muy bueno, ahora cuando cambias de paginas sigue conservando lo seleccionado ??

Re: FWH 2102: XBrowse:SetMultiSelectCol()

Posted: Mon Mar 15, 2021 10:57 pm
by Silvio.Falconi
Mr Nages,
when I select some records, can i print them?
Do U remember I noticed this problem last mounth

Re: FWH 2102: XBrowse:SetMultiSelectCol()

Posted: Tue Mar 16, 2021 7:06 am
by nageswaragunupudi
Silvio.Falconi wrote:Mr Nages,
when I select some records, can i print them?
Do U remember I noticed this problem last mounth


Yes.
The problem of single record also is fixed now.

Re: FWH 2102: XBrowse:SetMultiSelectCol()

Posted: Tue Mar 16, 2021 8:57 am
by richard-service
Mr. RAO

This function support TMySQL and MakeTotal

Re: FWH 2102: XBrowse:SetMultiSelectCol()

Posted: Tue Mar 16, 2021 9:01 am
by nageswaragunupudi
richard-service wrote:Mr. RAO

This function support TMySQL and MakeTotal


XBrowse's functionality works the same way for any datasource, whether it is tmysql, dbf, ado, etc.

Re: FWH 2102: XBrowse:SetMultiSelectCol()

Posted: Fri Mar 19, 2021 11:10 am
by Ariel
Mr. Rao,

I ask again, when paging with pageup / pagedown, is the selection preserved or is it lost?

regards.

Re: FWH 2102: XBrowse:SetMultiSelectCol()

Posted: Fri Mar 19, 2021 12:59 pm
by nageswaragunupudi
Ariel wrote:Mr. Rao,

I ask again, when paging with pageup / pagedown, is the selection preserved or is it lost?

regards.

Yes, preserved.
Sorry, I did not see your previous question.

Re: FWH 2102: XBrowse:SetMultiSelectCol()

Posted: Wed Mar 24, 2021 12:46 pm
by Ariel
Mr. Rao,


Continuing with the theme, if you press Page Down / Page Up and you have selected one or more items, the selection is lost.

regards.

Re: FWH 2102: XBrowse:SetMultiSelectCol()

Posted: Wed Mar 24, 2021 1:09 pm
by nageswaragunupudi
Ariel wrote:Mr. Rao,


Continuing with the theme, if you press Page Down / Page Up and you have selected one or more items, the selection is lost.

regards.


No.
They are not lost.
Please test after you download FWH2102.

Re: FWH 2102: XBrowse:SetMultiSelectCol()

Posted: Thu Mar 25, 2021 3:49 pm
by Ariel
Mr. Rao,

Perfect!!! Thanks.

Regards.

Re: FWH 2102: XBrowse:SetMultiSelectCol()

Posted: Thu Mar 25, 2021 4:25 pm
by Marc Venken
Is aSelected() used for the selections in the new way ?

I use this kind of functions many times

Code: Select all | Expand


Function markselected(oBrw4)
      if master->(flock())
        FOR I = 1 TO LEN(oBRW4:aSELECTED) // obrw:aSELECTED is an array containing recnos marked
          master->(dbgoto(oBRW4:aSELECTED[I]))
          replace master->selection with .t.
        next
        master->(dbunlock())
      endif
return NIL


 

Re: FWH 2102: XBrowse:SetMultiSelectCol()

Posted: Sat Mar 27, 2021 5:06 am
by nageswaragunupudi
This is a very roundabout way to maintain MASTER->SELECTION field.

We are forced to take the aid of arrays like "aSelected", etc., only when the database does not provide a field to indicate the selection status. When the database itself provides this field, we should use this field directly.

This is a sample:

Code: Select all | Expand

#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local oDlg, oFont, oBrw, oCol

   CreateDBF()

   USE MULSEL SHARED NEW

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-16
   DEFINE DIALOG oDlg SIZE 300,450 PIXEL TRUEPIXEL FONT oFont

   @ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE ALIAS() ;
      COLUMNS "SEL", "MONTH" ;
      HEADERS "" ;
      LINES NOBORDER FOOTERS

   WITH OBJECT oBrw
      :nStretchCol   := 2
      WITH OBJECT ( oCol := :aCols[ 1 ] )
         :SetCheck( nil, .t. )
         :nFooterType   := AGGR_COUNT
         :bSumCondition := { || ( oBrw:cAlias )->SEL }
         :bOnChange     := { || oCol:RefreshFooter() }
         :nHeadBmpNo    := { || If( oBrw:nLen == oCol:nCount, 1, 2 ) }
      END
      :MakeTotals()
      //
      :CreateFromCode()
   END

   @ 05, 20 BTNBMP PROMPT "INVERT" + CRLF + "SEL"  SIZE 80,50 PIXEL OF oDlg FLAT ACTION BrwSelect( oBrw, nil )
   @ 05,110 BTNBMP PROMPT "SELECT" + CRLF + "ALL"  SIZE 80,50 PIXEL OF oDlg FLAT ACTION BrwSelect( oBrw, .T. )
   @ 05,200 BTNBMP PROMPT "SELECT" + CRLF + "NONE" SIZE 80,50 PIXEL OF oDlg FLAT ACTION BrwSelect( oBrw, .F. )

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil

static function BrwSelect( oBrw, lSelect )

   local uBm   := oBrw:BookMark

   Eval( oBrw:bGoTop )
   repeat
      if lSelect == nil
         oBrw:oCol( 1 ):CheckToggle()
      else
         oBrw:oCol( 1 ):VarPut( lSelect )
      endif
   until ( Eval( oBrw:bSkip, 1 ) == 0 )
   oBrw:BookMark  := uBm
   oBrw:Refresh()
   oBrw:SetFocus()

return nil

static function CreateDBF()

   local n

   DBCREATE( "MULSEL", { { "SEL", "L", 1, 0 }, { "MONTH", "C", 10, 0 } }, ;
             "DBFCDX", .T., "MUL" )

   for n := 1 to 12
      APPEND BLANK
      FIELD->SEL     := ( N % 3 ) == 0
      FIELD->MONTH   := NTOCMONTH( n )
   next

   CLOSE MUL

return nil
 


Image

Re: FWH 2102: XBrowse:SetMultiSelectCol()

Posted: Sat Mar 27, 2021 9:37 am
by Silvio.Falconi
Nages,
is there SetMultiSelectCol() method on xbrowse.prg ?

Code: Select all | Expand


  Size: 4,108,800 bytes
   Compiler version: Harbour 3.2.0dev (r1904111533)
   FiveWin  version: FWH 21.02
   C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
   Windows version: 6.1, Build 7600

   Time from start: 0 hours 0 mins 0 secs
   Error occurred at: 27-03-2021, 10:05:37
   Error description: Error BASE/1004  Message not found: TXBROWSE:SETMULTISELECTCOL

Stack Calls
===========
   Called from: .\source\function\HARBOUR.PRG => _CLSSETERROR( 247 )
   Called from: xbrowse.prg => TXBROWSE:SETMULTISELECTCOL( 11509 )
   Called from: test.prg => MAIN( 96 )