xBrowse - ADO - SetMultiSelectCol - lAutosort

xBrowse - ADO - SetMultiSelectCol - lAutosort

Postby Maurizio » Tue Sep 06, 2022 8: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: Select all  Expand view  RUN
#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
User avatar
Maurizio
 
Posts: 825
Joined: Mon Oct 10, 2005 1:29 pm

Re: xBrowse - ADO - SetMultiSelectCol - lAutosort

Postby nageswaragunupudi » Tue Sep 06, 2022 6: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
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: xBrowse - ADO - SetMultiSelectCol - lAutosort SOLVED

Postby Maurizio » Wed Sep 07, 2022 6:56 am

Thanks Rao

The correct code is:

Code: Select all  Expand view  RUN
#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
User avatar
Maurizio
 
Posts: 825
Joined: Mon Oct 10, 2005 1:29 pm

Re: xBrowse - ADO - SetMultiSelectCol - lAutosort

Postby leandro » 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

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1676
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 69 guests