Page 1 of 1

Filter DCBOWSE of Array

Posted: Sat Dec 18, 2010 3:58 am
by jdsoft
Hello,

Maybe a silly question.
Is there a way to "Filter" lines in a DCBROWSE of array?
I would like to filter lines of type 1and type 2 controlled by the radiobutton.
So items of type 1 are only visible if type 1 is selected.
Items of type 2 are only visible if type 2 is selected.
The code below shows all types.

Suggestions are welcome.
Regards,
Jack Duijf

Code: Select all

#include "dcdialog.ch"
#pragma Library("dclipx.lib")

PROCEDURE MAIN

LOCAL GetList        := {}
LOCAL aData          := {}
LOCAL GetOptions     := {}
LOCAL oBrowse        := nil
LOCAL oBox           := oBox
LOCAL n              := 0
LOCAL nType          := 1

Aadd(aData,{1,"Item 1","Type 1",1})
Aadd(aData,{2,"Item 2","Type 2",2})
Aadd(aData,{3,"Item 3","Type 1",1})
Aadd(aData,{4,"Item 4","Type 2",2})
Aadd(aData,{5,"Item 5","Type 1",1})
Aadd(aData,{6,"Item 6","Type 2",2})
Aadd(aData,{7,"Item 7","Type 1",1})
Aadd(aData,{8,"Item 8","Type 2",2})
Aadd(aData,{9,"Item 9","Type 1",1})

@ 0,0    DCGROUP oBox SIZE 30,3 CAPTION "Show"
@ 1,1    DCRADIOBUTTON nType  PROMPT "Type 1" VALUE 1  PARENT oBox
@ 1,15   DCRADIOBUTTON nType  PROMPT "Type 2" VALUE 2  PARENT oBox
DCSETPARENT TO
@ 4,2    DCBROWSE oBrowse DATA aData SIZE 100,15  NOHSCROLL  ;
         PRESENTATION DC_BrowPres() ;
         ITEMSELECTED {||MsgBox(aData[n,2] + " selected.")} ;
         FIT POINTER n

DCBROWSECOL ELEMENT 1 HEADER "Id"    WIDTH  3 PARENT oBrowse
DCBROWSECOL ELEMENT 2 HEADER "Name"  WIDTH 15 PARENT oBrowse
DCBROWSECOL ELEMENT 3 HEADER "Type"  WIDTH 15 PARENT oBrowse

DCGETOPTIONS AUTORESIZE

DCREAD GUI FIT ADDBUTTONS MODAL ;
     OPTIONS GetOptions ;
     TITLE 'How to filter elements in a array?'
Return

Re: Filter DCBOWSE of Array

Posted: Sat Dec 18, 2010 10:24 am
by rdonnay
Jack -

Use the FILTER clause of @..DCBROWSE.

Like this:

Code: Select all

@ .. DCBROWSE ;
  FILTER {|a|a[4] == nType}
Roger

Re: Filter DCBOWSE of Array

Posted: Sat Dec 18, 2010 11:21 am
by jdsoft
Hello Roger,

Thank yoy for the suggestion.
I wasn's aware of this function, and missed it in the docs. :oops:

Regards,
Jack Duijf