Hide columns

Hide columns

Postby Silvio.Falconi » Mon Nov 16, 2015 7:48 am

It is possibile Hide some columns of xbrowse at init ?

for a sample I made:
oApp():oGrid := TXBrowse():New( oApp():oDlg )

.. columns...


oApp():oGrid:SetRDD()
oApp():oGrid:CreateFromCode()

oApp():oGrid:aCols[9]:lhide:=.t.


and it run at init


then if I use the popup menu at columns

Image




and I wish show the nineth column it show the column "Annotazione esercizio"

but when I press DEFAULT COLUMNS I wish return to state init ( with the oApp():oGrid:aCols[9]:lhide:=.t.)

or if the user select the oApp():oGrid:aCols[9] on menupopup it must be showed


the setcolumns method of xbrowse
Code: Select all  Expand view
METHOD SetColumns( nRow, nCol, nFlags ) CLASS TXBrowse

   local oMenu, oCol
   local nFor, nLen

   nLen := Len( ::aCols )

   MENU oMenu POPUP
      if ::l2007
         if WndMain() != nil .and. WndMain():oMenu != nil .and. WndMain():oMenu:l2010
            oMenu:l2010    := .t.
         else
            oMenu:l2007    := .t.
         endif
      endif
      Menuitem "Default Columns" ACTION ( ;
                                ASort( ::aCols, nil, nil, { |x,y| x:nCreationOrder < y:nCreationorder } ), ;
                                AEval( ::aCols, { |o| o:lHide := .f. } ), ;
                                ::GetDisplayCols(), ;
                                ::Refresh() )
      separator
      for nFor := 1 to nLen
         oCol := ::aCols[ nFor ]
         MenuAddItem( oCol:cHeader, , !oCol:lHide, ;
            ( Len(::aDisplay) != 1 .or. ocol:nPos != 1 ), ;
            GenMenuBlock( ::aCols, nFor ) )
      next
   ENDMENU

   ACTIVATE POPUP oMenu AT nRow, nCol OF Self

return nil




the command

Menuitem "Default Columns" ACTION ( ;
ASort( ::aCols, nil, nil, { |x,y| x:nCreationOrder < y:nCreationorder } ), ;
AEval( ::aCols, { |o| o:lHide := .f. } ), ;
::GetDisplayCols(), ;
::Refresh() )


show all columns and not that columns I set at init
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: 7048
Joined: Thu Oct 18, 2012 7:17 pm

Re: Hide columns

Postby FranciscoA » Mon Nov 16, 2015 7:28 pm

The following sample code, functional , shows how to display or hide columns in a xbrowse .

Initially, the desired columns are displayed, hiding the rest , then all columns of browse are displayed .

Everything runs by clicking any column header. It does not intend to modify TXBrowse class .

I hope it can helps for your implementation.


Code: Select all  Expand view
REQUEST DBFCDX
//---------------------------------
FUNCTION ColsHideShow()
local oDlg, oBrw, oFont
local aCols2Hide := {2,4,5,6}, lHide

XbrNumFormat( 'A', .t. )

USE customer NEW SHARED ALIAS CUST VIA 'DBFCDX'

DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
DEFINE DIALOG oDlg SIZE 800,400 PIXEL TITLE "Hide-Show Columns in xBrowse" FONT oFont

@ 10,10 XBROWSE oBrw ;
      COLUMNS 'First', 'Age', 'Salary', 'Street', 'City', 'State' ;
      SIZE -10,-10 PIXEL ;
      OF oDlg ;
      ALIAS 'CUST' ;
      CELL LINES AUTOSORT NOBORDER FOOTERS

WITH OBJECT oBrw
     :CreateFromCode()
END

AEval(oBrw:aCols,{|o| o:bLClickHeader := {|nRow,nCol,nFlags,oCol| lHide:= If(lHide,.f.,.t.), HidShwCls(oBrw,aCols2Hide, lHide) } })

ACTIVATE DIALOG oDlg CENTERED ON INIT ( lHide:=.t., HidShwCls(oBrw, aCols2Hide, lHide) )

    RELEASE FONT oFont
    Cust->(dbCloseArea())
RETURN NIL
//----------------------------------------------
Static Function HidShwCls(oBrw,aCols2Hide, lHide)

if lHide
   AEval(aCols2Hide, {|o,n| oBrw:aCols[aCols2Hide[n]]:Hide() })
else
   AEval(oBrw:aCols, {|o,n| oBrw:aCols[n]:Show() })
endif

oBrw:Refresh()
Return nil
 
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2158
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: Hide columns

Postby Silvio.Falconi » Tue Nov 17, 2015 8:09 am

Dear Francisco,
the sample run ok here but I wish explain you.

when I open mt customer application table I have default column sample {2,4,5,6}
I save the state on inifile when the final user close the table and restore the state when the final user open the table

What I Wish:

1. if the final user select the other column then the state must be changed sample {1,2,3,4,5,6}
2. If the final user select the option "Default columns" ( see setcolumn method xbrowse changed) the xbrowse must return to show the default column {2,4,5,6} and save the state.

I cannot make the second problem because when I select "Default columns" the xbrowse class show all fields into table
it should show only the default columns {2,4,5,6}

please try to change setcolumns at xbrowse class to see what it do

Mr. Rao should make a small change to set the default columns. then the end user can select which columns to show more or less.

The developer should take this opportunity and make sure that the end user can select which columns to show.
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: 7048
Joined: Thu Oct 18, 2012 7:17 pm

Re: Hide columns

Postby Silvio.Falconi » Thu Nov 19, 2015 5:31 pm

Any solution ?
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: 7048
Joined: Thu Oct 18, 2012 7:17 pm

Re: Hide columns

Postby nageswaragunupudi » Thu Nov 19, 2015 11:29 pm

aDefCols := { 2,4,5,6 }

.............

@ r,c, BUTTON "Def Cols" SIZE .......... ACTION ;
AEval( oBrw:aCols, { |o| If( AScan( aDefCols, o:nCreationOrder ) > 0, o:Show(), o:Hide() ) } )
Regards

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

Re: Hide columns

Postby FranciscoA » Fri Nov 20, 2015 4:08 am

Thanks, Mr. Rao.

Silvio.
Here the same example, a bit improved. Try it, please.

You can select:
Default Columns, All Columns, Previous Columns.

Code: Select all  Expand view
REQUEST DBFCDX
//---------------------------------
FUNCTION ColsHideShow()
local oDlg, oBrw, oFont
local aDefCols := {1,3}, aPrevCols, lPrevCols := .t.
local bShowDefCols := {|| AEval( oBrw:aCols, { |o| If( AScan( aDefCols, o:nCreationOrder ) > 0, o:Show(), o:Hide() ) } ) }

XbrNumFormat( 'A', .t. )

USE customer NEW SHARED ALIAS CUST VIA 'DBFCDX'

DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
DEFINE DIALOG oDlg SIZE 800,400 PIXEL TITLE "Hide-Show Columns in xBrowse" FONT oFont

@ 10,10 XBROWSE oBrw ;
      COLUMNS 'First', 'Age', 'Salary', 'Street', 'City', 'State' ;
      SIZE -10,-10 PIXEL ;
      OF oDlg ;
      ALIAS 'CUST' ;
      CELL LINES AUTOSORT NOBORDER FOOTERS

WITH OBJECT oBrw
     :CreateFromCode()
END

AEval(oBrw:aCols,{|o| o:bRClickHeader := {|nRow,nCol,nFlags,oCol| MenuCols(oBrw,bShowDefCols,@aPrevCols, @lPrevCols) } })

ACTIVATE DIALOG oDlg CENTERED ON INIT ( Eval(bShowDefCols) )

    RELEASE FONT oFont
    Cust->(dbCloseArea())
RETURN NIL

//-------------------------------------------
FUNCTION MenuCols(oBrw,bShowDefCols,aPrevCols, lPrevCols)
   local oMenu, oCol
   local nFor, nLen
   local nRow := 1, nCol := 1

   local bPrevCols := {|| aPrevCols := oBrw:GetDisplayCols() }
   local bShowHide := {|| AEval( oBrw:aCols, { |o| If( AScan( aPrevCols, o:nCreationOrder ) > 0, o:Show(), o:Hide() ) } ) }
   local bShowAllCols  := {|| AEval( oBrw:aCols, { |o| o:Show() } ) }

   nLen := Len( oBrw:aCols )

   MENU oMenu POPUP 2010
      MENUITEM "Default Columns"  ACTION ( Eval(bPrevCols), Eval(bShowDefCols), lPrevCols := .t. )
      MENUITEM "All Columns"      ACTION ( Eval(bPrevCols), Eval(bShowAllCols), lPrevCols := .t. )
      MENUITEM "Previous Columns" ACTION ( Eval(bShowHide), Eval(bPrevCols), lPrevCols := .f. )  WHEN lPrevCols

      for nFor := 1 to nLen
         oCol := oBrw:aCols[ nFor ]
         MenuAddItem( oCol:cHeader, , !oCol:lHide, ;
            ( Len(oBrw:aDisplay) != 1 .or. oCol:nPos != 1 ), ;
            GenMenuBlock( oBrw:aCols, nFor ) )
      next
   ENDMENU

   ACTIVATE POPUP oMenu WINDOW oBrw AT nRow, nCol
return nil
//-----------------------------------------
static function GenMenuBlock( aCols, nFor )
   local oCol := aCols[ nFor ]
return {|| iif( oCol:lHide, oCol:Show(), oCol:Hide() ) }
 
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2158
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: Hide columns

Postby Silvio.Falconi » Fri Nov 20, 2015 8:17 am

Mr Nages, Mr Francisco

I made this test

on xbrowse.prg add this data

DATA aCols2Hide AS ARRAY INIT Array(0)


change the method setcolumns()
Code: Select all  Expand view



METHOD SetColumns( nRow, nCol, nFlags ) CLASS TXBrowse

   local oMenu, oCol
   local nFor, nLen

   nLen := Len( ::aCols )

   MENU oMenu POPUP
      if ::l2007
         if WndMain() != nil .and. WndMain():oMenu != nil .and. WndMain():oMenu:l2010
            oMenu:l2010    := .t.
         else
            oMenu:l2007    := .t.
         endif
      endif
      Menuitem "Dedault Columns" ACTION ( ;
                                ASort( ::aCols, nil, nil, { |x,y| x:nCreationOrder < y:nCreationorder } ), ; //
                                AEval( ::aCols, { |o| If( AScan( ::aCols2Hide, o:nCreationOrder ) > 0, o:Show(),o:Hide() ) } ) ,;
                                ::GetDisplayCols(), ;
                                ::Refresh() )

                                SEPARATOR

      Menuitem "All Columns " ACTION ( ;   // old
                                ASort( ::aCols, nil, nil, { |x,y| x:nCreationOrder < y:nCreationorder } ), ;
                                AEval( ::aCols, { |o| o:lHide := .f. } ), ;
                                ::GetDisplayCols(), ;
                                ::Refresh() )

      SEPARATOR
      for nFor := 1 to nLen
         oCol := ::aCols[ nFor ]
         MenuAddItem( oCol:cHeader, , !oCol:lHide, ;
            ( Len(::aDisplay) != 1 .or. ocol:nPos != 1 ), ;
            GenMenuBlock( ::aCols, nFor ) )
      next
   ENDMENU

   ACTIVATE POPUP oMenu AT nRow, nCol OF Self

return nil

l




this is the small test sample

Code: Select all  Expand view



#include"fivewin.ch"


REQUEST DBFCDX
    //---------------------------------
    FUNCTION ColsHideShow()
    local oDlg, oBrw, oFont


    XbrNumFormat( 'A', .t. )

    USE customer NEW SHARED ALIAS CUST VIA 'DBFCDX'

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
    DEFINE DIALOG oDlg SIZE 800,400 PIXEL TITLE "Hide-Show Columns in xBrowse" FONT oFont

    @ 10,10 XBROWSE oBrw ;
          COLUMNS 'First', 'Age', 'Salary', 'Street', 'City', 'State' ;
          SIZE -10,-10 PIXEL ;
          OF oDlg ;
          ALIAS 'CUST' ;
          CELL LINES AUTOSORT NOBORDER FOOTERS

    WITH OBJECT oBrw
         :aCols2Hide := {2,4,5,6}
         :CreateFromCode()
    END

  ACTIVATE DIALOG oDlg CENTERED

        RELEASE FONT oFont
        Cust->(dbCloseArea())
    RETURN NIL

 




It run ok .... only at init not set the column I want

but if I add on test before the activate dialog this line

AEval( oBrw:aCols, { |oCol| If( AScan( oBrw:aCols2Hide, oCol:nCreationOrder ) > 0, oCol:Show(),oCol:Hide() ) } )

run at init also...

Rao, where I must insert this line on xbrowse class ?
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: 7048
Joined: Thu Oct 18, 2012 7:17 pm

Re: Hide columns

Postby FranciscoA » Fri Nov 20, 2015 3:59 pm

Silvio, I think I found a solution.

Let me to make some tests more.

As soon as posible I'll post it here.
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2158
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: Hide columns

Postby Silvio.Falconi » Fri Nov 20, 2015 6:02 pm

there was an error .
it found 0 as array and erase all columns then the xbrowse class put one column ( the first) as default
this because on old xbrowse tables where is not the array aCols2Hide

please change on setcolumns

IF len(::aCols2Hide)!=0
Menuitem "Default columns" ACTION ( ;
ASort( ::aCols, nil, nil, { |x,y| x:nCreationOrder < y:nCreationorder } ), ; //
AEval( ::aCols, { |o| If( AScan( ::aCols2Hide, o:nCreationOrder ) > 0, o:Show(),o:Hide() ) } ) ,;
::GetDisplayCols(), ;
::Refresh() )
SEPARATOR
Endif

Now run ok

please you must insert

AEval( oBrw:aCols, { |oCol| If( AScan( oBrw:aCols2Hide, oCol:nCreationOrder ) > 0, oCol:Show(),oCol:Hide() ) } )

before the command oBrw:RestoreState( cState )
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: 7048
Joined: Thu Oct 18, 2012 7:17 pm

Re: Hide columns

Postby FranciscoA » Sat Nov 21, 2015 3:01 am

Silvio.
My solution, modifying xbrowse. Please test it and tell us.

New DATAS;
Code: Select all  Expand view
  DATA aDefaultCols  INIT ARRAY( 0 )   //FranciscoA
   DATA aPreviousCols INIT ARRAY( 0 )   //FranciscoA
 


New method:
Code: Select all  Expand view
//-----------------------------------------------------------------------------//
METHOD SetUserCols(lDefCols)  CLASS TXBrowse               //FranciscoA
local aCols

DEFAULT lDefCols := .t.

aCols := if(lDefCols, ::aDefaultCols, ::aPreviousCols )

if Len( aCols ) != 0
   AEval( ::aCols, { |o| If( AScan( aCols, o:nCreationOrder ) > 0, o:Show(),o:Hide() ) } )
endif

Return nil

 


Method modified
Code: Select all  Expand view
//-----------------------------------------------------// FranciscoA
METHOD SetColumns( nRow, nCol, nFlags ) CLASS TXBrowse

   local oMenu, oCol
   local nFor, nLen
   local bPrevCols := {|| ::aPreviousCols := ::GetDisplayCols() }

   nLen := Len( ::aCols )

   MENU oMenu POPUP
      if ::l2007
         if WndMain() != nil .and. WndMain():oMenu != nil .and. WndMain():oMenu:l2010
            oMenu:l2010    := .t.
         else
            oMenu:l2007    := .t.
         endif
      endif

      if Len( ::aDefaultCols ) != 0
         Menuitem "Default Columns"   ACTION ( Eval( bPrevCols ), ::SetUserCols(.T.), ::Refresh() )
         Menuitem "All Columns"       ACTION ( Eval( bPrevCols ), AEval( ::aCols, { |o| o:lHide := .f. } ) , ::Refresh() )
         Menuitem "Old Columns"       ACTION ( ::SetUserCols(.F.) , ::Refresh() )
        SEPARATOR
      endif

      for nFor := 1 to nLen
         oCol := ::aCols[ nFor ]
         MenuAddItem( oCol:cHeader, , !oCol:lHide, ;
            ( Len(::aDisplay) != 1 .or. ocol:nPos != 1 ), ;
            GenMenuBlock( ::aCols, nFor ) )
      next
   ENDMENU

   ACTIVATE POPUP oMenu AT nRow, nCol OF Self

return nil
 


Test:
Code: Select all  Expand view
REQUEST DBFCDX
//----------------------
FUNCTION ColsHideShow()
local oDlg, oBrw, oFont
local aDefCols := {1,3}

XbrNumFormat( 'A', .t. )

USE customer NEW SHARED ALIAS CUST VIA 'DBFCDX'

DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
DEFINE DIALOG oDlg SIZE 800,400 PIXEL TITLE "Hide-Show Columns in xBrowse" FONT oFont

@ 10,10 XBROWSE oBrw ;
      COLUMNS 'First', 'Age', 'Salary', 'Street', 'City', 'State' ;
      SIZE -10,-10 PIXEL ;
      OF oDlg ;
      ALIAS 'CUST' ;
      CELL LINES AUTOSORT NOBORDER FOOTERS

WITH OBJECT oBrw
     :aDefaultCols := aDefCols
     :SetUserCols()

     :CreateFromCode()
END

ACTIVATE DIALOG oDlg CENTERED

    RELEASE FONT oFont
    Cust->(dbCloseArea())
RETURN NIL
 
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2158
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: Hide columns

Postby Silvio.Falconi » Sat Nov 21, 2015 8:55 am

run ok but I not understood why "Old columns"

I save the state when I close the table
and re open the state at init


please try this
you can see if I save a state sample 1,3,6 ( set these columns and then close the exe) then it save right on inifile ( see the customer.ini)

when you re open the exe it show the column 1 3 and not the state saved before


Code: Select all  Expand view


#include"fivewin.ch"

REQUEST DBFCDX
    //----------------------
    FUNCTION ColsHideShow()
    local oDlg, oBrw, oFont
    local aDefCols := {1,3}
    local cIniFile:=".\customer.ini"
    local cState := GetPvProfString("Browse", "CUState","", cIniFile)
    local nOrder := VAL(GetPvProfString("Browse", "MVOrder","1", cIniFile))
    local nRecno := VAL(GetPvProfString("Browse", "MVRecno","1", cIniFile))
    XbrNumFormat( 'A', .t. )

    USE customer NEW SHARED ALIAS CU VIA 'DBFCDX'

    DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
    DEFINE DIALOG oDlg SIZE 800,400 PIXEL TITLE "Hide-Show Columns in xBrowse" FONT oFont

    @ 10,10 XBROWSE oBrw ;
          COLUMNS 'First', 'Age', 'Salary', 'Street', 'City', 'State' ;
          SIZE -10,-10 PIXEL ;
          OF oDlg ;
          ALIAS 'CU' ;
          CELL LINES AUTOSORT NOBORDER FOOTERS

    WITH OBJECT oBrw
         :aDefaultCols := aDefCols
         :SetUserCols()

         :CreateFromCode()
    END


      oBrw:RestoreState( cState )


       cu->(DbSetOrder(nOrder))



   if nRecNo < cu->(LastRec()) .AND. nRecno != 0
      cu->(DbGoTo(nRecno))
   else
      cu->(DbGoTop())
   endif







   ACTIVATE DIALOG oDlg CENTERED ;
ON INIT (oBrw:SetFocus() ) ;
VALID (oBrw:nLen := 0,;
             WritePProString("Browse","CUState",oBrw:SaveState(),cIniFile),;
              WritePProString("Browse","CUOrder",Ltrim(Str(CU->(OrdNumber()))),cIniFile) ,;
              WritePProString("Browse","CURecno",Ltrim(Str(CU->(Recno()))),cIniFile),;
              DbCloseAll(),oDlg := NIL, oBrw := NIL,  .t. )

        RELEASE FONT oFont
      *  Cu->(dbCloseArea())
    RETURN NIL
 
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: 7048
Joined: Thu Oct 18, 2012 7:17 pm

Re: Hide columns

Postby FranciscoA » Sat Nov 21, 2015 7:04 pm

run ok but I not understood why "Old columns"

I added those menu items (Old columns and All columns ) because I am preventing a future need in my software, and I wanted to share it , if it is useful to anyone. In any case, you can skip that.

when you re open the exe it show the column 1 3 and not the state saved before

Please try the following example and say if this is the behavior you want .
Code: Select all  Expand view
REQUEST DBFCDX
    //----------------------//  con xbrowse modificado
    FUNCTION ColsHideShow()
    local oDlg, oBrw, oFont
    local cIniFile:=".\customer.ini"
    local cState := GetPvProfString("Browse", "CUSTstate","", cIniFile)

    USE customer NEW SHARED ALIAS "CUST" VIA "DBFCDX"

    DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
    DEFINE DIALOG oDlg SIZE 800,400 PIXEL TITLE "Hide-Show Columns in xBrowse" FONT oFont

    XbrNumFormat( 'A', .t. )

    @ 10,10 XBROWSE oBrw ;
          COLUMNS "First", "Age", "Salary", "Street", "City", "State" ;
          SIZE -10,-10 PIXEL ;
          OF oDlg ;
          ALIAS "CUST" ;
          CELL LINES AUTOSORT NOBORDER FOOTERS

    WITH OBJECT oBrw
         :SetUserCols()

         :CreateFromCode()
    END

    oBrw:RestoreState( cState )

    ACTIVATE DIALOG oDlg CENTERED  ;
        ON INIT ( oBrw:aDefaultCols := oBrw:GetDisplayCols() )
   
        WritePProString("Browse","CUSTstate",oBrw:SaveState(),cIniFile)
        CUST->(dbCloseArea())
        RELEASE FONT oFont
RETURN NIL
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2158
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: Hide columns

Postby FranciscoA » Sat Nov 21, 2015 8:06 pm

Or better look, this way?

Code: Select all  Expand view
REQUEST DBFCDX
    //----------------------//  con xbrowse modificado
    FUNCTION ColsHideShow()
    local oDlg, oBrw, oFont
    local cIniFile:=".\customer.ini"
    local cState := GetPvProfString("Browse", "CUSTstate","", cIniFile)

    USE customer NEW SHARED ALIAS "CUST" VIA "DBFCDX"

    DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
    DEFINE DIALOG oDlg SIZE 800,400 PIXEL TITLE "Hide-Show Columns in xBrowse" FONT oFont

    XbrNumFormat( 'A', .t. )

    @ 10,10 XBROWSE oBrw ;
          COLUMNS "First", "Age", "Salary", "Street", "City", "State" ;
          SIZE -10,-10 PIXEL ;
          OF oDlg ;
          ALIAS "CUST" ;
          CELL LINES AUTOSORT NOBORDER FOOTERS

    WITH OBJECT oBrw
         :RestoreState( cState )
         :aDefaultCols := oBrw:GetDisplayCols()  
         :SetUserCols()
         :CreateFromCode()
    END

    ACTIVATE DIALOG oDlg CENTERED
   
        WritePProString("Browse","CUSTstate",oBrw:SaveState(),cIniFile)
        CUST->(dbCloseArea())
        RELEASE FONT oFont
RETURN NIL
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2158
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: Hide columns

Postby FranciscoA » Sun Nov 22, 2015 5:41 pm

Here's something more compact, erasing SetUserCols() (not need anymore). It is the version that I save for me.

Code: Select all  Expand view
.......................
   DATA aDefaultCols  INIT ARRAY( 0 )  
   DATA aPreviousCols INIT ARRAY( 0 )
.......................

//----------------------------------------------------------------
METHOD SetColumns( nRow, nCol, nFlags ) CLASS TXBrowse

   local oMenu, oCol
   local nFor, nLen

   local aCols, lDefCols
   local bPrevCols := {|| ::aPreviousCols := ::GetDisplayCols() }
   local bUserCols := {|| aCols := if(lDefCols, ::aDefaultCols, ::aPreviousCols ) ,;
                          if( Len( aCols ) != 0, AEval( ::aCols, { |o| If( AScan( aCols, o:nCreationOrder ) > 0, o:Show(),o:Hide() ) } ) ,)}

   nLen := Len( ::aCols )

   MENU oMenu POPUP
      if ::l2007  
         if WndMain() != nil .and. WndMain():oMenu != nil .and. WndMain():oMenu:l2010
            oMenu:l2010    := .t.
         else
            oMenu:l2007    := .t.
         endif
      endif


      if Len( ::aDefaultCols ) != 0
         Menuitem "Default Columns"   ACTION ( Eval( bPrevCols ), lDefCols:=.t., Eval( bUserCols ), ::Refresh() )
         Menuitem "All Columns"       ACTION ( Eval( bPrevCols ), AEval( ::aCols, { |o| o:lHide := .f. } ) , ::Refresh() )
         Menuitem "Previous Columns"  ACTION ( lDefCols:=.f., Eval( bUserCols ), ::Refresh() )
         SEPARATOR
      endif


      for nFor := 1 to nLen
         oCol := ::aCols[ nFor ]
         MenuAddItem( oCol:cHeader, , !oCol:lHide, ;
            ( Len(::aDisplay) != 1 .or. oCol:nPos != 1 ), ;
            GenMenuBlock( ::aCols, nFor ) )
      next
   ENDMENU

   ACTIVATE POPUP oMenu AT nRow, nCol OF Self

return nil


TEST:
REQUEST DBFCDX
//----------------------//  con xbrowse modificado method setcolumns()
FUNCTION ColsHideShow()
local oDlg, oBrw, oFont
local cIniFile:=".\customer.ini"
local cState := GetPvProfString("Browse", "CUSTstate","", cIniFile)

  USE customer NEW SHARED ALIAS "CUST" VIA "DBFCDX"

  DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
  DEFINE DIALOG oDlg SIZE 800,400 PIXEL TITLE "Hide-Show Columns in xBrowse" FONT oFont

  XbrNumFormat( 'A', .t. )

  @ 10,10 XBROWSE oBrw ;
          COLUMNS "First", "Age", "Salary", "Street", "City", "State" ;
          SIZE -10,-10 PIXEL ;
          OF oDlg ;
          ALIAS "CUST" ;
          CELL LINES AUTOSORT NOBORDER FOOTERS

  WITH OBJECT oBrw
      :RestoreState( cState )
      :aDefaultCols := oBrw:GetDisplayCols()
      :CreateFromCode()
  END

  ACTIVATE DIALOG oDlg CENTERED
   
     WritePProString("Browse","CUSTstate",oBrw:SaveState(),cIniFile)
     CUST->(dbCloseArea())
     RELEASE FONT oFont
RETURN NIL
 
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2158
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: Hide columns

Postby Silvio.Falconi » Sun Nov 22, 2015 5:58 pm

thanks Francisco, good Job!
it seems run also here
I hope Mr Rao insert on next package ( xbrowse)
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: 7048
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 64 guests