Page 1 of 1

DCBROWSECOL ... HIDE

Posted: Thu Feb 01, 2024 9:00 am
by skiman
Hi,

I'm trying to hide/show a column in a browse. I don't succeed to get this working as it should.

I can hide, but when I want to show it again, it looks as another column is overwritten. I tried refreshall, forcestable() but it doens't work as expected.

Below is my sample code which demonstrates the problem.
- You can hide column 2.
- When you want to show it again, it comes instead of column1 which looks as it disappears.

Code: Select all

function testbrowse()
****************************************
Local getlist := {} , oBrowse
Local aTestData := { {"abc","xyz",123} }
Local lDisplay := .T.

@ 1,1 dcbrowse oBrowse data atestdata SIZE 40,10 FIT
DCBROWSECOL ELEMENT 1 HEADER "Col 1 " PARENT oBrowse WIDTH 10
DCBROWSECOL ELEMENT 2 HEADER "Col 2 " PARENT oBrowse WIDTH 10 HIDE {|| !lDisplay }
DCBROWSECOL ELEMENT 3 HEADER "Col 3 " PARENT oBrowse WIDTH 10

@12,10 dcpushbuttonxp ;
	CONFIG amain(2,17) ;
	CAPTION 'SHOW Col 2' notabstop ;
	SIZE 20,1  ;
		ACTION {||lDisplay := .T. ,DC_GetRefresh(getlist), oBrowse:refreshall(), setAppfocus(oBrowse) }
@12,32 dcpushbuttonxp ;
	CONFIG amain(2,17) ;
	CAPTION 'HIDE Col 2' notabstop ;
	SIZE 20,1  ;
		ACTION {||lDisplay:=.F. ,DC_GetRefresh(getlist),obrowse:gotop(),oBrowse:refreshall(), oBrowse:forceStable(), setAppfocus(oBrowse) }

DCREAD GUI ;
	TITLE 'Test Hide/Show Col' FIT 
	
return nil

Re: DCBROWSECOL ... HIDE

Posted: Sun Feb 04, 2024 8:58 am
by slobodan1949
* Solution variant A "HALF eXpress++"
****************************************
function testbrowse()
****************************************
Local getlist := {} , oBrowse
Local aTestData := { {"abc","xyz",123} }

@ 1,1 dcbrowse oBrowse data atestdata SIZE 40,10 FIT
DCBROWSECOL ELEMENT 1 HEADER "Col 1 " PARENT oBrowse WIDTH 10 OBJECT c1
DCBROWSECOL ELEMENT 2 HEADER "Col 2 " PARENT oBrowse WIDTH 10 OBJECT c2
DCBROWSECOL ELEMENT 3 HEADER "Col 3 " PARENT oBrowse WIDTH 10 OBJECT c3

@12,10 dcpushbuttonxp ;
CAPTION 'HIDE Col 2' notabstop ;
SIZE 20,1 ;
ACTION {|| ;
c2:Hide(),;
oBrowse:refreshall(), setAppfocus(oBrowse) }
@12,32 dcpushbuttonxp ;
CAPTION 'SHOW Col 2' notabstop ;
SIZE 20,1 ;
ACTION {|| ;
c2:Show(),;
oBrowse:refreshall(), setAppfocus(oBrowse) }

DCREAD GUI ;
TITLE 'Test Hide/Show Col' FIT
return nil




* Solution variant B "COMPLETELY eXpress++"
****************************************
function testbrowse()
****************************************
Local getlist := {} , oBrowse
Local aTestData := { {"abc","xyz",123} }

Local cHide := memoread("lHide") // "1" or ""
IF cHide = "1"
lHide := .T.
ELSE
lHide := .F.
ENDIF

@ 1,1 dcbrowse oBrowse data atestdata SIZE 40,10 FIT
DCBROWSECOL ELEMENT 1 HEADER "Col 1 " PARENT oBrowse WIDTH 10
DCBROWSECOL ELEMENT 2 HEADER "Col 2 " PARENT oBrowse WIDTH 10 HIDE {|| lHide }
DCBROWSECOL ELEMENT 3 HEADER "Col 3 " PARENT oBrowse WIDTH 10

PRIVATE restart := .F.

@12,10 dcpushbuttonxp ;
CAPTION 'HIDE Col 2' notabstop ;
SIZE 20,1 ;
ACTION {|| ;
memowrit("lHide","1"),;
restart:=.T.,;
DC_ReadGuiEvent(DCGUI_EXIT_OK,GetList)}

@12,32 dcpushbuttonxp ;
CAPTION 'SHOW Col 2' notabstop ;
SIZE 20,1 ;
ACTION {|| ;
memowrit("lHide",""),;
restart:=.T.,;
DC_ReadGuiEvent(DCGUI_EXIT_OK,GetList)}

DCREAD GUI ;
TITLE 'Test Hide/Show Col' FIT

if restart==.T.
testbrowse()
endif
return nil

* Solution variant C "FULL eXpress++"
* Consult the 'Roger Donnay Group'

Re: DCBROWSECOL ... HIDE

Posted: Mon Feb 05, 2024 1:51 am
by skiman
Hi,

Thanks for the response.

With Solution A the column is not really hidden. It gets a blank column, but it still remains in the browse.
Solution be can also be accomplished with a do while. I was hoping on a more efficient solution.

I will see, or I use solution B or I create multiple browses on a static and use a show/hide system on the statics. Just have to test what's best concerning 'flickering' of the screen.

Re: DCBROWSECOL ... HIDE

Posted: Mon Feb 05, 2024 5:41 am
by rdonnay
I recommend looking at the source code of SqlQuery.prg.

The browse system allows you to collapse and restore columns.
First you tag columns with a right-click in the header, then select collapse.

Re: DCBROWSECOL ... HIDE

Posted: Mon Feb 12, 2024 6:12 am
by k-insis
Can you try setting columns horizontal size to zero and leaving vertical size as is ?
skiman wrote: Mon Feb 05, 2024 1:51 am Hi,

Thanks for the response.

With Solution A the column is not really hidden. It gets a blank column, but it still remains in the browse.
Solution be can also be accomplished with a do while. I was hoping on a more efficient solution.

I will see, or I use solution B or I create multiple browses on a static and use a show/hide system on the statics. Just have to test what's best concerning 'flickering' of the screen.

Re: DCBROWSECOL ... HIDE

Posted: Tue Feb 13, 2024 2:43 am
by SlavkoDam
Hi,

This is a code from my library PowerWin for hide/show a browse column. You can use it for free. It is simple, elegant, efficient and makes no flickers on the screen. To understand the code, you should read the XbpBrowse() source code in SOURCE\RUNTIME\DUI. This is the right way how to do that task.

Code: Select all

FUNCTION BRWCOLHIDE(oBrw,col_pos)
**
LOCAL oPanel,aPos,wdt,I, oCol := oBrw:getColumn(col_pos)
**
IF !oCol:isVisible() .OR. ASCAN(oBrw:setLeftFrozen(),col_pos) > 0 .OR. ;
   ASCAN(oBrw:setRightFrozen(),col_pos) > 0
  RETURN .F.
ENDIF
oPanel = oCol:setParent()
oPanel:lockUpdate(.T.)
wdt = oCol:currentSize()[1]
oCol:hide()
FOR I = (col_pos + 1) TO oBrw:colCount
  oCol = oBrw:getColumn(I)
  aPos = oCol:currentPos()
  oCol:setPos({aPos[1] - wdt,aPos[2]})
NEXT
oBrw:panEnd():panHome()
oPanel:lockUpdate(.F.)
oPanel:invalidateRect()
RETURN .T.

FUNCTION BRWCOLSHOW(oBrw,col_pos)
**
LOCAL oPanel,aPos,wdt,I, oCol := oBrw:getColumn(col_pos)
**
IF oCol:isVisible() .OR. ASCAN(oBrw:setLeftFrozen(),col_pos) > 0 .OR. ;
   ASCAN(oBrw:setRightFrozen(),col_pos) > 0
  RETURN .F.
ENDIF
oPanel = oCol:setParent()
oPanel:lockUpdate(.T.)
wdt = oCol:currentSize()[1]
oCol:show()
FOR I = oBrw:colCount TO (col_pos + 1) STEP -1
  oCol = oBrw:getColumn(I)
  aPos = oCol:currentPos()
  oCol:setPos({aPos[1] + wdt,aPos[2]})
NEXT
oBrw:panEnd():panHome()
oPanel:lockUpdate(.F.)
oPanel:invalidateRect()
RETURN .T.


Re: DCBROWSECOL ... HIDE

Posted: Wed Feb 14, 2024 9:59 am
by skiman
Hi SlavcoDam,

Thanks for the sample code. I will try it.

Re: DCBROWSECOL ... HIDE

Posted: Sun Feb 25, 2024 4:34 am
by SlavkoDam
Hi Cris,

I am interested did you try my code and does it work well?

Re: DCBROWSECOL ... HIDE

Posted: Mon Feb 26, 2024 12:53 am
by skiman
Hi,

Your code is working fine.