FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour xBrowse - ADO - SetMultiSelectCol - lAutosort
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM
xBrowse - ADO - SetMultiSelectCol - lAutosort
Posted: Tue Sep 06, 2022 08:20 AM
Ciao RAO
I have an xbrowse with SetMultiSelectCol and lAutosort (as example) .
If the customer selects columns and then changes the oRs order (since SetMultiSelectCol works with oRs: AbsolutePosition)
the result of the selected columns is wrong .
I think SetMultiSelectCol should work on the table ID .
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main( cParam )

   local oDlg, oFont, oFixed, oGet, oBrw
   local oCn, oRs, cSql,oBtn

   SetGetColorFocus()
   TMultiGet():lClrFocus   := .t.
   SET DATE ITALIAN
   SET CENTURY ON

   FW_SetUnicode( .t. )

   if Empty( cParam )
      oCn   := FW_DemoDB()
   else
      oCn   := maria_Connect( cParam )
   endif

   if oCn == nil
      return nil
   endif

   //cSql  := "SELECT Now()"
   oRs   := oCn:RowSet( "select * from clients" )
  
   //oRs   := oCn:RowSet( cSql )

   DEFINE FONT oFont  NAME "TAHOMA"         SIZE 0,-14
   DEFINE FONT oFixed NAME "LUCIDA CONSOLE" SIZE 0,-18

   DEFINE DIALOG oDlg SIZE 900,700 PIXEL TRUEPIXEL FONT oFont ;
      TITLE FWVERSION + " : MySQLR"
      
   @ 1, 20 BUTTON oBtn PROMPT "List aselect "SIZE 100, 40 ACTION  Listselect(oBrw,oRs)
   
   @ 1, 80 BUTTON oBtn PROMPT "End"SIZE 100, 40 ACTION  oDlg:End()
                         

   @ 100,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg DATASOURCE oRs ;
      AUTOCOLS CELL LINES NOBORDER FOOTERS FASTEDIT 

   WITH OBJECT oBrw
      :bRecSelHeader    := { || "RecNo" }
      :bRecSelData      := { |o| o:BookMark }
      :bRecSelFooter    := { || oBrw:nLen }
      :nRecSelWidth     := "99999"
      :lAutosort := .T. 
     
      :SetMultiSelectCol()
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED  
   RELEASE FONT oFont, oFixed
return nil  
Static Function Listselect(oBrw,oRs)   
Local i 
   xbrowse(oBrw:aSelected)
   FOR i := 1 TO len(oBrw:aSelected)
       oRs:AbsolutePosition := oBrw:aSelected[i]
   
       ? oRs:Fields( "ID" ):Value
   
   NEXT
   
Return nil


Maurizio
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: xBrowse - ADO - SetMultiSelectCol - lAutosort
Posted: Tue Sep 06, 2022 06:20 PM
If the customer selects columns and then changes the oRs order (since SetMultiSelectCol works with oRs: AbsolutePosition)


NO.

oBrw:aSelected is NOT an array of oRs:AbsolutePositions.
It is an array of oRs:BookMarks

BookMark of a RecordSet is like RECNO() of DBF. Does not change with sorting.
AbsolutePosition of a RecordSet is like OrdKeyNo() of DBF, which changes when sorted.

So, you are safe even when sorting.
Regards



G. N. Rao.

Hyderabad, India
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM
Re: xBrowse - ADO - SetMultiSelectCol - lAutosort SOLVED
Posted: Wed Sep 07, 2022 06:56 AM
Thanks Rao

The correct code is:

Code (fw): Select all Collapse
#include "fivewin.ch"

function Main( cParam )

   local oDlg, oFont, oFixed, oGet, oBrw
   local oCn, oRs, cSql,oBtn

   SetGetColorFocus()
   TMultiGet():lClrFocus   := .t.
   SET DATE ITALIAN
   SET CENTURY ON

   FW_SetUnicode( .t. )

   if Empty( cParam )
      oCn   := FW_DemoDB()
   else
      oCn   := maria_Connect( cParam )
   endif

   if oCn == nil
      return nil
   endif

   //cSql  := "SELECT Now()"
   oRs   := oCn:RowSet( "select * from clients" )
  
   //oRs   := oCn:RowSet( cSql )

   DEFINE FONT oFont  NAME "TAHOMA"         SIZE 0,-14
   DEFINE FONT oFixed NAME "LUCIDA CONSOLE" SIZE 0,-18

   DEFINE DIALOG oDlg SIZE 900,700 PIXEL TRUEPIXEL FONT oFont ;
      TITLE FWVERSION + " : MySQLR"
      
   @ 1, 20 BUTTON oBtn PROMPT "List aselect "SIZE 100, 40 ACTION  Listselect(oBrw,oRs)
   
   @ 1, 80 BUTTON oBtn PROMPT "End"SIZE 100, 40 ACTION  oDlg:End()
                         

   @ 100,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg DATASOURCE oRs ;
      AUTOCOLS CELL LINES NOBORDER FOOTERS FASTEDIT 

   WITH OBJECT oBrw
      :bRecSelHeader    := { || "RecNo" }
      :bRecSelData      := { |o| o:BookMark }
      :bRecSelFooter    := { || oBrw:nLen }
      :nRecSelWidth     := "99999"
      :lAutosort := .T. 
     
      :SetMultiSelectCol()
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED  
   RELEASE FONT oFont, oFixed
return nil  
Static Function Listselect(oBrw,oRs)   
Local i 
   xbrowse(oBrw:aSelected)
   FOR i := 1 TO len(oBrw:aSelected)
      // oRs:AbsolutePosition := oBrw:aSelected[i]
       oRs:BookMark  :=oBrw:aSelected[i]
   
       ? oRs:Fields( "ID" ):Value
   
   NEXT
   
Return nil
Posts: 1816
Joined: Wed Oct 26, 2005 02:49 PM
Re: xBrowse - ADO - SetMultiSelectCol - lAutosort
Posted: Thu Dec 21, 2023 12:31 AM
Maurizio, gracias por publicar el código, funciona de maravilla :D :D :D
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 25.01 ] [ xHarbour 64 bits) ]

Continue the discussion