Xbrowse changing columns online ( ReArrangeCols)

Xbrowse changing columns online ( ReArrangeCols)

Postby Silvio.Falconi » Tue Jan 17, 2023 10:38 am

Image

I'm trying to convert an old inventory management source where I used a listbox.

The substantial problem is that the first two columns (CVEPRO,DESCRI) must be inverted online according to the number corresponding to the combobox.

The combobox is connected to Xbrowse because I use it to search fields.

Practically it happens that the columns don't change and if I insert the option :SetMultiSelectCol() adding a column at the beginning it undoes the other columns and I don't know how to do it.

you can see that the fourth column is repeated the third why ?

I did a small test to show the problem, send me your mailbox where I can send the dbf to try with the test




Code: Select all  Expand view

 
#include "FiveWin.ch"

static oWinMain,oT
static oControl

function Main()


    *oControl := TDatabase():Open(,"Control" ,"DBFCDX", .t.)
    * xbrowser oControl

   DEFINE WINDOW oWinMain TITLE "Test" MDI ;
      MENU BuildMenu()

   ACTIVATE WINDOW oWinMain

return nil

function BuildMenu()

   local oMenu

   MENU oMenu
      MENUITEM "Test"
      MENU
         MENUITEM "Articoli" ACTION Articoli()
      ENDMENU
      oMenu:AddMdi()
   ENDMENU

return oMenu

Function Articoli()
   local nCla:=1
   local oFont1
 local  cHead1:=IF(nCla=1,"Codice","Descrizione")
 local  cHead2:=IF(nCla=1,"Descrizione","Codice")
 local  nS1:= IF(nCla=1,125,365)
 local  nS2:= IF(nCla=1,365,125)
 local oArticoli
 local oLbx,aCols
 local oBar,oWinArticoli,oTabs


   local cSeek:=Space(100)
   local oGet
   local oSay:=array(4)
   local cOrder := ""



 IF oWinArticoli == nil
    oT:= MA_130():New()

     oArticoli := TCatalogo():New()
     oArticoli:SetOrder(1 )
     oArticoli:GoTop()
     cTitolo     := "Anagrafica articoli"


  /*  aCols  := { ;
               {  ""  ,  cHead1             ,,   nS1, },;
               { "MR" ,  "MR"               ,,   50,  },;
               { ""   ,  cHead2             ,,   nS2, },;
               { ""   ,  ""                 ,,   50,  },;
               { "Esistenza",  ""           ,,   50,  }}

    */


    aCols  := { ;
               { "CVEPRO"    ,  "Codice"             ,,   100, },;
               { "MR"        ,  "MR"                 ,,   50,  },;
               { "DESCRI"    ,  "Descrizione"        ,,   150, },;
                { "",  ""                              ,,   50,  },;
                { "Esistenza",  ""                     ,,   50,  }}



   DEFINE WINDOW oWinArticoli MDICHILD ;
      FROM 0, 0 TO 24, 79   ;
      TITLE cTitolo       ;
      of oWinMain

  DEFINE FONT oFont1 NAME "Tahoma" SIZE 0, -12 BOLD
 DEFINE BUTTONBAR oBar TOP _3D OF oWinArticoli

   DEFINE BUTTON RESOURCE "Nuevo"    NOBORDER OF oBar          ;
      TOOLTIP "aggiungi"                                   ;
      ACTION  NIL
   DEFINE BUTTON RESOURCE "editar"   NOBORDER OF oBar          ;
      TOOLTIP "Editar"                                           ;
      ACTION NIL
   DEFINE BUTTON RESOURCE "Elimin"   NOBORDER OF oBar          ;
      TOOLTIP "Eliminar"  ACTION NIL



    @ 4,231 say oSay[1] Prompt "Cerca :" SIZE 46,12 PIXEL OF oBar FONT oFont1
    @ 4,435 say oSay[2] Prompt "in" SIZE 40,12 PIXEL OF oBar FONT oFont1


    @ 2, 280 GET oGet VAR cSeek SIZE 150,22 PIXEL OF oBar  ;
                      BITMAP "ELIMINA" ACTION  (cSeek    := Space( 100 ),;
                      oLbx:Seek( "" ), oLbx:refresh(), oGet:refresh())
                      oGet:lBtnTransparent :=.t.


//Tabs
 @ 00, 00 TABS oTabs OF oWinArticoli ;
    PROMPT     "Codice", "Descrizione"  ;
    COLORS     GetSysColor(13), GetSysColor(14) ;
    ACTION     ( Orden(oTabs,oArticoli,oLbx,oWinArticoli),;
               oLbx:oSortCbx:set(oTabs:nOption) )



//Xbrowse
@ 0,0 XBROWSE oLbx OF oWinArticoli ;
      DATASOURCE oArticoli COLUMNS aCols ;
      AUTOSORT ;
      NOBORDER CELL LINES

 WITH OBJECT oLbx
            :nRowHeight          := 30
            :l2007               := .F.
            :l2015               := .T.
            :nColDividerStyle    := LINESTYLE_LIGHTGRAY
            :nRowDividerStyle    := LINESTYLE_LIGHTGRAY
            :nStretchCol         := STRETCHCOL_WIDEST
            :lAllowRowSizing     := .F.
            :lAllowColSwapping   := .F.
            :lAllowColHiding     := .F.
            :nRecSelColor     :=   nRgb( 245,244,234)
            :lIncrFilter      := .t.

             :bOnSort          := { |b,oCol| oLbx:Seek( "" ), ;
                                   oLbx:cFilterFld := oCol:cExpr, ;
                                   oLbx:SetFocus() }

           * :bClrStd    := { || { CLR_BLACK, If( oLbx:oCol( 1 ):Value, 0x80ffff, CLR_WHITE ) } }
            :bClrHeader       := {|| { ,nRgb( 245,244,234) } }
            :bClrFooter       := {|| { ,nRgb( 245,244,234) } }
            :lDrawBorder := .t.
            :lHScroll  := .f.
            :SetMultiSelectCol()
            :oSeek := oGet
            :nMarqueeStyle       := MARQSTYLE_HIGHLWIN7



         WITH OBJECT oLbx:aCols[ 2 ]
           :cHeader := cHead1
           :nWidth:= nS1
           :bEditValue := { ||  Desp_Fld1(oLbx:oSortCbx:nat,oArticoli)  }
        END

         WITH OBJECT oLbx:aCols[ 3 ]
           :cHeader := cHead2
           :nWidth:= nS2
          :bEditValue := { ||  Desp_Fld2(oLbx:oSortCbx:nat,oArticoli)  }
         END


         WITH OBJECT oLbx:aCols[ 5 ]
              :AddResource("I_Nor")
              :AddResource("I_Min")
              :AddResource("C_Pal")
              :AddResource("I_Lot")
              :AddResource("I_Gpo")
              :AddResource("I_Grd")
              :bBmpData := { || Desp_Mar(oArticoli) }
             END

             WITH OBJECT oLbx:aCols[ 6 ]
              :bEditValue := { ||  Desp_Exi(oArticoli)  }
             END

            :CreateFromCode()
         END



//Combobox

 @ 2, 450 COMBOBOX oLbx:oSortCbx VAR oLbx:cSortOrder;
        SIZE 200,400 PIXEL OF oBar HEIGHTGET 18 STYLE CBS_DROPDOWN ;
        ON change (oTabs:nOption := oLbx:oSortCbx:nat,;
                   oTabs:refresh(),;
                   eval(oTabs:baction),;
                   Sel_Index(oLbx:oSortCbx:nat,oArticoli,oLbx))


       oWinArticoli:oClient := oLbx
       oWinArticoli:oControl := oLbx

    oTabs:nOption :=1
   oWinArticoli:oBottom := oTabs

   else
      oWinArticoli:SetFocus()
   endif

  ACTIVATE WINDOW oWinArticoli MAXIMIZED ;
           VALID     (oWinArticoli:=Nil,.T.)
RETURN NIL





//----------------------------------------------------//
//shows the minimum stock o if it is a lot or  Group
Function Desp_Mar(oArticoli)
   LOCAL nB:=1
   nB:=IF(oArticoli:Minimo<>0 .AND. oArticoli:TotExi<oArticoli:Minimo,2,nB)
   nB:=IF(oArticoli:Lote ,4,nB)
   nB:=IF(oArticoli:Grupo,5,nB)
   nB:=IF(oArticoli:Lote .and. oArticoli:Grupo,6,nB)
   nB:=IF(AScan(oT:aSel,oArticoli:CvePro)<>0 ,3,nB)
RETURN (nB)

//----------------------------------------------------//
  //shows the current existence
Function Desp_Exi(oArticoli)
   LOCAL nTot:=IF(Abs(oArticoli:TotExi)<0.01,0,oArticoli:TotExi)
RETURN (Tran(Abs(nTot),"99,999,999.99"))

//----------------------------------------------------//
Function Desp_Fld1( nInd,oArticoli)
   LOCAL cFld
   local nBrw:=1           //Control->nBrw=2
  * local nBrw:= oControl:nBrw
   IF nInd=1
      cFld:=oArticoli:CvePro
   ELSE
      IF nBrw=2
         cFld:=oArticoli:Descri+CRLF+oArticoli:DesAdi
      ELSE
         cFld:=oArticoli:Descri
      ENDIF
   ENDIF
RETURN (cFld)
//----------------------------------------------------//
Function Desp_Fld2( nInd,oArticoli)
   LOCAL cFld
    local nBrw:=1           //Control->nBrw=2
   * local nBrw:= oControl:nBrw
    IF nInd=2
      cFld:=oArticoli:CvePro
   ELSE
      IF nBrw=2
         cFld:=oArticoli:Descri+CRLF+oArticoli:DesAdi
      ELSE
         cFld:=oArticoli:Descri
      ENDIF
   ENDIF
   RETURN (cFld)

//----------------------------------------------------//

Function Sel_Index(nInd,oArticoli,oLbx)
   oArticoli:SetOrder(nInd)
   IF nInd=1
         WITH OBJECT oLbx:aCols[ 2 ]
           :cHeader :="Codice"
           :nWidth:= 125
         END
         WITH OBJECT oLbx:aCols[ 3 ]
          :cHeader :="Descrizione"
          :nWidth:= 365
         END
   ENDIF

   IF nInd=2
         WITH OBJECT oLbx:aCols[ 2 ]
           :cHeader :="Descrizione"
           :nWidth:= 365
         END
         WITH OBJECT oLbx:aCols[ 3 ]
          :cHeader :="Codice"
          :nWidth:= 125
         END
   ENDIF

   oLbx:Refresh()
   oLbx:SetFocus()
RETURN (Nil)


//--------------------------------------------------------//
 Function Orden(oTabs,oArticoli,oLbx,oWinArticoli)
   IF oTabs:nOption == 1       //CvePro
      oArticoli:SetOrder(1)
   ELSEIF oTabs:nOption == 2   //Descri
      oArticoli:SetOrder(2)
   ENDIF
   oLbx:refresh()
   oWinArticoli:Update()
   RETURN NIL






//--------------------------------------------------------------------------------------------//
CLASS TXData from TDataBase
 DATA cDbfPath init cFilePath(GetModuleFileName( GetInstance() ))  + "Data\"    //for test
 DATA cEXEPath init cFilePath(GetModuleFileName( GetInstance() ))     //for test

ENDCLASS


CLASS TCatalogo from TXData
   METHOD New()
ENDCLASS

METHOD New( lShared ) CLASS TCatalogo
   Default lShared := .t.
   ::super:Open(,::cDbfPath + "
Catalogo" ,"DBFCDX", lShared)
   if ::use()
      ::setOrder(1)
      ::gotop()
   endif
RETURN Self





 CLASS MA_130
   DATA oDat, aEnt, aSal, aSel , nCamD
   DATA lIni, lObs, nMov, nSEnt, nSSal
   DATA cLin, cMar, cLyM, nFil , nCamE
   METHOD New() CONSTRUCTOR
ENDCLASS

METHOD New() CLASS MA_130
   ::lObs:=.T.
   ::lIni:=.T.
   ::nFil:=0
   ::nMov:=0
   ::nCamD:=0
   ::nCamE:=0
   ::nSEnt:=0
   ::nSSal:=0
   ::aSel:={}
   ::oDat:=Array(23)
   ::aEnt:=Array(12)
   ::aSal:=Array(12)
   ::cLin:="
<Tutte>"
   ::cMar:="
<Tutte>"
   ::cLyM:="
"
RETURN (Self)














I tried also to make

Code: Select all  Expand view

@ 0,0 XBROWSE oLbx OF oWinArticoli ;
      DATASOURCE oArticoli;
      COLUMNS  Desp_Fld1(oLbx,oArticoli), "MR", Desp_Fld2(oLbx,oArticoli), ;
                       Desp_Mar(oArticoli), Desp_Exi(oArticoli) ;
       HEADERS cHead1  , "MR", cHead2, "","Existencia" ;
       SIZES  nS1, 25,nS2, 15, 65 ;
      AUTOSORT ;
      NOBORDER CELL LINES

....

Function Desp_Fld1( oLbx,oArticoli)
   LOCAL cFld
   local nInd:= oLbx:oSortCbx:nat

   local nBrw:=1           //Control->nBrw=2
  * local nBrw:= oControl:nBrw
   IF nInd=1
      cFld:=oArticoli:CvePro
   ELSE
      IF nBrw=2
         cFld:=oArticoli:Descri+CRLF+oArticoli:DesAdi
      ELSE
         cFld:=oArticoli:Descri
      ENDIF
   ENDIF
RETURN (cFld)
//----------------------------------------------------//
Function Desp_Fld2( oLbx,oArticoli)
   LOCAL cFld
   local nInd:=oLbx:oSortCbx:nat
    local nBrw:=1           //Control->nBrw=2
   * local nBrw:= oControl:nBrw
    IF nInd=2
      cFld:=oArticoli:CvePro
   ELSE
      IF nBrw=2
         cFld:=oArticoli:Descri+CRLF+oArticoli:DesAdi
      ELSE
         cFld:=oArticoli:Descri
      ENDIF
   ENDIF
   RETURN (cFld)

 


But then make error because it not found oLbx:oSortCbx
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6867
Joined: Thu Oct 18, 2012 7:17 pm

Re: Xbrowse changing columns online ( ReArrangeCols)

Postby Silvio.Falconi » Wed Jan 18, 2023 10:32 am

If I add RearrangeCols when I change the item on the combobox not run ok


Code: Select all  Expand view
Function Orden(oTabs,oArticoli,oLbx,oWinArticoli)
    local cOrder

   local  aColumns[1] := { ;
               { "CVEPRO"    ,  "Codice"             ,,   100, },;
               { "MR"        ,  "MR"                 ,,   50,  },;
               { "DESCRI"    ,  "Descrizione"        ,,   150, },;
               { "",  ""                              ,,   50,  },;
               { "",  "Esistenza"                     ,,   50,  }}

  local     aColumns[2] := { ;
               { "DESCRI"    ,  "Descrizione"        ,,   150, },;
               { "MR"        ,  "MR"                 ,,   50,  },;
               { "CVEPRO"    ,  "Codice"             ,,   100, },;
               { "",  ""                              ,,   50,  },;
               { "",  "Esistenza"                     ,,   50,  }}


    IF oTabs:nOption == 1       //CvePro
      oArticoli:SetOrder(1)
      cOrder := "Codice"
   ELSEIF oTabs:nOption == 2   //Descri
      oArticoli:SetOrder(2)
      cOrder := "Descrizione"
   ENDIF

   oLbx:ReArrangeCols( aColumns[oLbx:oSortCbx:nat] )
   oLbx:oSortCbx:refresh()
   oLbx:cSortOrder:=cOrder


   oLbx:refresh()
   oWinArticoli:Update()
   RETURN NIL




all source test
Code: Select all  Expand view

#include "FiveWin.ch"

static oWinMain,oT
static oControl

function Main()


    *oControl := TDatabase():Open(,"Control" ,"DBFCDX", .t.)
    * xbrowser oControl

   DEFINE WINDOW oWinMain TITLE "Test" MDI ;
      MENU BuildMenu()

   ACTIVATE WINDOW oWinMain

return nil

function BuildMenu()

   local oMenu

   MENU oMenu
      MENUITEM "Test"
      MENU
         MENUITEM "Articoli" ACTION Articoli()
      ENDMENU
      oMenu:AddMdi()
   ENDMENU

return oMenu

Function Articoli()
   local nCla:=1
   local oFont1
 local  cHead1:=IF(nCla=1,"Codice","Descrizione")
 local  cHead2:=IF(nCla=1,"Descrizione","Codice")
 local  nS1:= IF(nCla=1,125,365)
 local  nS2:= IF(nCla=1,365,125)
 local oArticoli
 local oLbx,aCols
 local oBar,oWinArticoli,oTabs
 local aColumns:=array(2)

   local cSeek:=Space(100)
   local oGet
   local oSay:=array(4)
   local cOrder := ""


 IF oWinArticoli == nil
    oT:= MA_130():New()

     oArticoli := TCatalogo():New()
     oArticoli:SetOrder(1 )
     oArticoli:GoTop()
     cTitolo     := "Anagrafica articoli"


  /*  aCols  := { ;
               {  ""  ,  cHead1             ,,   nS1, },;
               { "MR" ,  "MR"               ,,   50,  },;
               { ""   ,  cHead2             ,,   nS2, },;
               { ""   ,  ""                 ,,   50,  },;
               { "",  "Esistenza"           ,,   50,  }}

    */


    aCols  := { ;
               { "CVEPRO"    ,  "Codice"             ,,   100, },;
               { "MR"        ,  "MR"                 ,,   50,  },;
               { "DESCRI"    ,  "Descrizione"        ,,   150, },;
                { "",  ""                              ,,   50,  },;
                { "",  "Esistenza"                     ,,   50,  }}

    aColumns[1] := { ;
               { "CVEPRO"    ,  "Codice"             ,,   100, },;
               { "MR"        ,  "MR"                 ,,   50,  },;
               { "DESCRI"    ,  "Descrizione"        ,,   150, },;
               { "",  ""                              ,,   50,  },;
               { "",  "Esistenza"                     ,,   50,  }}

      aColumns[2] := { ;
               { "DESCRI"    ,  "Descrizione"        ,,   150, },;
               { "MR"        ,  "MR"                 ,,   50,  },;
               { "CVEPRO"    ,  "Codice"             ,,   100, },;
               { "",  ""                              ,,   50,  },;
               { "",  "Esistenza"                     ,,   50,  }}

   DEFINE WINDOW oWinArticoli MDICHILD ;
      FROM 0, 0 TO 24, 79   ;
      TITLE cTitolo       ;
      of oWinMain

  DEFINE FONT oFont1 NAME "Tahoma" SIZE 0, -12 BOLD
 DEFINE BUTTONBAR oBar TOP _3D OF oWinArticoli

   DEFINE BUTTON RESOURCE "Nuevo"    NOBORDER OF oBar          ;
      TOOLTIP "aggiungi"                                   ;
      ACTION  NIL
   DEFINE BUTTON RESOURCE "editar"   NOBORDER OF oBar          ;
      TOOLTIP "Editar"                                           ;
      ACTION NIL
   DEFINE BUTTON RESOURCE "Elimin"   NOBORDER OF oBar          ;
      TOOLTIP "Eliminar"  ACTION NIL



    @ 4,231 say oSay[1] Prompt "Cerca :" SIZE 46,12 PIXEL OF oBar FONT oFont1
    @ 4,435 say oSay[2] Prompt "in" SIZE 40,12 PIXEL OF oBar FONT oFont1


    @ 2, 280 GET oGet VAR cSeek SIZE 150,22 PIXEL OF oBar  ;
                      BITMAP "ELIMINA" ACTION  (cSeek    := Space( 100 ),;
                      oLbx:Seek( "" ), oLbx:refresh(), oGet:refresh())
                      oGet:lBtnTransparent :=.t.


//Tabs   oLbx:oSortCbx:set(oTabs:nOption)
 @ 00, 00 TABS oTabs OF oWinArticoli ;
    PROMPT     "Codice", "Descrizione"  ;
    COLORS     GetSysColor(13), GetSysColor(14) ;
    ACTION     Orden(oTabs,oArticoli,oLbx,oWinArticoli,aColumns)





//Xbrowse
@ 0,0 XBROWSE oLbx OF oWinArticoli ;
      DATASOURCE oArticoli COLUMNS aCols ;
      AUTOSORT ;
      NOBORDER CELL LINES



 WITH OBJECT oLbx
            :nRowHeight          := 30
            :l2007               := .F.
            :l2015               := .T.
            :nColDividerStyle    := LINESTYLE_LIGHTGRAY
            :nRowDividerStyle    := LINESTYLE_LIGHTGRAY
            :nStretchCol         := STRETCHCOL_WIDEST
            :lAllowRowSizing     := .F.
            :lAllowColSwapping   := .F.
            :lAllowColHiding     := .F.
            :nRecSelColor     :=   nRgb( 245,244,234)
            :lIncrFilter      := .t.

             :bOnSort          := { |b,oCol| oLbx:Seek( "" ), ;
                                   oLbx:cFilterFld := oCol:cExpr, ;
                                   oLbx:SetFocus() }

           * :bClrStd    := { || { CLR_BLACK, If( oLbx:oCol( 1 ):Value, 0x80ffff, CLR_WHITE ) } }
            :bClrHeader       := {|| { ,nRgb( 245,244,234) } }
            :bClrFooter       := {|| { ,nRgb( 245,244,234) } }
            :lDrawBorder := .t.
            :lHScroll  := .f.
            :SetMultiSelectCol()
            :oSeek := oGet
            :nMarqueeStyle       := MARQSTYLE_HIGHLWIN7


         WITH OBJECT oLbx:aCols[ 5 ]
              :AddResource("I_Nor")
              :AddResource("I_Min")
              :AddResource("C_Pal")
              :AddResource("I_Lot")
              :AddResource("I_Gpo")
              :AddResource("I_Grd")
              :bBmpData := { || Desp_Mar(oArticoli) }
             END

             WITH OBJECT oLbx:aCols[ 6 ]
              :bEditValue := { ||  Desp_Exi(oArticoli)  }
             END

            :CreateFromCode()
         END

//Combobox

 @ 2, 450 COMBOBOX oLbx:oSortCbx VAR oLbx:cSortOrder;
        SIZE 200,400 PIXEL OF oBar HEIGHTGET 18 STYLE CBS_DROPDOWN ;
        ON CHANGE (oTabs:nOption := oLbx:oSortCbx:nat,;
                   oTabs:refresh(),;
                   eval(oTabs:baction) )


       oWinArticoli:oClient := oLbx
       oWinArticoli:oControl := oLbx

    oTabs:nOption :=1
   oWinArticoli:oBottom := oTabs

   else
      oWinArticoli:SetFocus()
   endif

  ACTIVATE WINDOW oWinArticoli MAXIMIZED ;
           VALID     (oWinArticoli:=Nil,.T.)
RETURN NIL





//----------------------------------------------------//
//shows the minimum stock o if it is a lot or  Group
Function Desp_Mar(oArticoli)
   LOCAL nB:=1
   nB:=IF(oArticoli:Minimo<>0 .AND. oArticoli:TotExi<oArticoli:Minimo,2,nB)
   nB:=IF(oArticoli:Lote ,4,nB)
   nB:=IF(oArticoli:Grupo,5,nB)
   nB:=IF(oArticoli:Lote .and. oArticoli:Grupo,6,nB)
   nB:=IF(AScan(oT:aSel,oArticoli:CvePro)<>0 ,3,nB)
RETURN (nB)

//----------------------------------------------------//
  //shows the current existence
Function Desp_Exi(oArticoli)
   LOCAL nTot:=IF(Abs(oArticoli:TotExi)<0.01,0,oArticoli:TotExi)
RETURN (Tran(Abs(nTot),"99,999,999.99"))

//----------------------------------------------------//
Function Desp_Fld1( oLbx,oArticoli)
   LOCAL cFld
   local nInd := oLbx:oSortCbx:nat

   local nBrw:=1           //Control->nBrw=2
   * local nBrw:= oControl:nBrw



   IF nInd=1
      cFld:=oArticoli:CvePro
   ELSE
      IF nBrw=2
         cFld:=oArticoli:Descri+CRLF+oArticoli:DesAdi
      ELSE
         cFld:=oArticoli:Descri
      ENDIF
   ENDIF

RETURN (cFld)
//----------------------------------------------------//
Function Desp_Fld2( oLbx,oArticoli)
   LOCAL cFld

   local nInd:= oLbx:oSortCbx:nat

    local nBrw:=1           //Control->nBrw=2
   * local nBrw:= oControl:nBrw
    IF nInd=2
      cFld:=oArticoli:CvePro
   ELSE
      IF nBrw=2
         cFld:=oArticoli:Descri+CRLF+oArticoli:DesAdi
      ELSE
         cFld:=oArticoli:Descri
      ENDIF
   ENDIF
   RETURN (cFld)

//----------------------------------------------------//

Function Sel_Index(nInd,oArticoli,oLbx)
 *  oArticoli:SetOrder(nInd)

   IF nInd=1

         WITH OBJECT oLbx:aCols[ 2 ]
           :cHeader :="Codice"
           :nWidth:= 125
            :bEditValue := { || oArticoli:CvePro  }
         END
         WITH OBJECT oLbx:aCols[ 3 ]
          :cHeader :="Descrizione"
          :nWidth:= 365
           :bEditValue := { || oArticoli:Descri  }
        END

   ENDIF

   IF nInd=2
         WITH OBJECT oLbx:aCols[ 2 ]
           :cHeader :="Descrizione"
           :nWidth:= 365
            :bEditValue := { || oArticoli:Descri  }
         END
         WITH OBJECT oLbx:aCols[ 3 ]
          :cHeader :="Codice"
          :nWidth:= 125
          :bEditValue := { || oArticoli:CvePro  }
         END
      ENDIF

    oLbx:oSortCbx:set(nInd)
   oLbx:Refresh()
   oLbx:SetFocus()
RETURN (Nil)


//--------------------------------------------------------//
 Function Orden(oTabs,oArticoli,oLbx,oWinArticoli,aColumns)
    local cOrder

    IF oTabs:nOption == 1       //CvePro
      oArticoli:SetOrder(1)
      cOrder := "Codice"
   ELSEIF oTabs:nOption == 2   //Descri
      oArticoli:SetOrder(2)
      cOrder := "Descrizione"
   ENDIF

   oLbx:ReArrangeCols( aColumns[oLbx:oSortCbx:nat] )
   oLbx:oSortCbx:refresh()
   oLbx:cSortOrder:=cOrder
   oLbx:refresh()
   oWinArticoli:Update()
   RETURN NIL






//--------------------------------------------------------------------------------------------//
CLASS TXData from TDataBase
 DATA cDbfPath init cFilePath(GetModuleFileName( GetInstance() ))  + "Data\"    //for test
 DATA cEXEPath init cFilePath(GetModuleFileName( GetInstance() ))     //for test

ENDCLASS


CLASS TCatalogo from TXData
   METHOD New()
ENDCLASS

METHOD New( lShared ) CLASS TCatalogo
   Default lShared := .t.
   ::super:Open(,::cDbfPath + "
Catalogo" ,"DBFCDX", lShared)
   if ::use()
      ::setOrder(1)
      ::gotop()
   endif
RETURN Self





 CLASS MA_130
   DATA oDat, aEnt, aSal, aSel , nCamD
   DATA lIni, lObs, nMov, nSEnt, nSSal
   DATA cLin, cMar, cLyM, nFil , nCamE
   METHOD New() CONSTRUCTOR
ENDCLASS

METHOD New() CLASS MA_130
   ::lObs:=.T.
   ::lIni:=.T.
   ::nFil:=0
   ::nMov:=0
   ::nCamD:=0
   ::nCamE:=0
   ::nSEnt:=0
   ::nSSal:=0
   ::aSel:={}
   ::oDat:=Array(23)
   ::aEnt:=Array(12)
   ::aSal:=Array(12)
   ::cLin:="
<Tutte>"
   ::cMar:="
<Tutte>"
   ::cLyM:="
"
RETURN (Self)





Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6867
Joined: Thu Oct 18, 2012 7:17 pm

Re: Xbrowse changing columns online ( ReArrangeCols)

Postby nageswaragunupudi » Mon Jan 30, 2023 9:33 pm

iI provide a sample using customer.dbf in the samples folder.
You may use the same logic for your dbf.

Code: Select all  Expand view

#include "fivewin.ch"

function Main()

   local oDlg, oBrw, oCbx
   local nCbx := 1

   USE CUSTOMER

   DEFINE DIALOG oDlg SIZE 800,400 PIXEL TRUEPIXEL RESIZABLE

   @ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE "CUSTOMER" AUTOCOLS ;
      HEADERS "Code", "FirstName" ;
      CELL LINES NOBORDER

   WITH OBJECT oBrw
      :SetMultiSelectCol()
      :CreateFromCode()
   END

   @ 10,20 COMBOBOX oCbx VAR nCbx ITEMS { "Code", "FirstName" } SIZE 150,30 PIXEL OF oDlg ;
      ON CHANGE CbxChange( oCbx, oBrw )

   ACTIVATE DIALOG oDlg CENTERED

return nil

static function CbxChange( oCbx, oBrw )

   if oCbx:nAt == 1
      oBrw:ReArrangeCols( { oBrw:oMultiSelCol, "CODE", "FIRSTNAME" }, .t., .f., .f. )
   else
      oBrw:ReArrangeCols( { oBrw:oMultiSelCol, "FIRSTNAME", "CODE" }, .t., .f., .f. )
   endif
   oBrw:SetFocus()

return nil
 


Image
Regards

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

Re: Xbrowse changing columns online ( ReArrangeCols)

Postby Silvio.Falconi » Tue Jan 31, 2023 8:34 am

nageswaragunupudi wrote:iI provide a sample using customer.dbf in the samples folder.
You may use the same logic for your dbf.

Code: Select all  Expand view

#include "fivewin.ch"

function Main()

   local oDlg, oBrw, oCbx
   local nCbx := 1

   USE CUSTOMER

   DEFINE DIALOG oDlg SIZE 800,400 PIXEL TRUEPIXEL RESIZABLE

   @ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE "CUSTOMER" AUTOCOLS ;
      HEADERS "Code", "FirstName" ;
      CELL LINES NOBORDER

   WITH OBJECT oBrw
      :SetMultiSelectCol()
      :CreateFromCode()
   END

   @ 10,20 COMBOBOX oCbx VAR nCbx ITEMS { "Code", "FirstName" } SIZE 150,30 PIXEL OF oDlg ;
      ON CHANGE CbxChange( oCbx, oBrw )

   ACTIVATE DIALOG oDlg CENTERED

return nil

static function CbxChange( oCbx, oBrw )

   if oCbx:nAt == 1
      oBrw:ReArrangeCols( { oBrw:oMultiSelCol, "CODE", "FIRSTNAME" }, .t., .f., .f. )
   else
      oBrw:ReArrangeCols( { oBrw:oMultiSelCol, "FIRSTNAME", "CODE" }, .t., .f., .f. )
   endif
   oBrw:SetFocus()

return nil
 


Image



Sorry Nages,
here not run ok when I put it into my app
I have the combobox for the Search on the xbrowse and it link to tab control

Code: Select all  Expand view

 @ 2, 450 COMBOBOX oLbx:oSortCbx VAR oLbx:cSortOrder;
        SIZE 200,400 PIXEL OF oBar HEIGHTGET 18 STYLE CBS_DROPDOWN ;
       ON CHANGE  ( CbxChange( oLbx:oSortCbx, oLbx ),;  //your function
                   oTabs:nOption := oLbx:oSortCbx:nat,;
                   oTabs:refresh() )
 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6867
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 67 guests