bb.donnay-software.com

Donnay Software Web Forums
It is currently Sat May 30, 2020 11:19 pm

All times are UTC - 7 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: List Box Select Only One
PostPosted: Fri Oct 14, 2016 6:34 am 
Offline
User avatar

Joined: Tue Jul 28, 2015 5:15 am
Posts: 94
I have this code that show Items in a List Box.
You can select one or more Items.
You can select all items and you may Clear all items with 2 buttons.

Now I would like to modify this and force only one Item can be selected.
Like at each selection, it does a clear all prior selection.

Here is the code.

Code:
FUNCTION sLISTBOX(aITEMS)

   LOCAL GetList := {}, aFields:={}, cField:={}
   LOCAL oListBox

   aFields := aITEMS

   @ 0,0 DCLISTBOX cField LIST aFields ;
      FONT "10.Courier" ;
      SIZE 15,10 ;
      OBJECT oListBox
      // SELECT {2,4,5,6,7}

   @ 0, 17 DCPUSHBUTTON ;
      CAPTION '~Mark All' ;
      SIZE 10, 1.1 ;
      FONT '8.MS Sans Serif' ;
      ACTION {|| AEVAL(aFields, {|x,i| oListBox:setData(i, .T.)}), ;
                 DC_VarFromListBox(oListBox)} ;
      RELATIVE oListBox

   @ 1.5, 17 DCPUSHBUTTON ;
      CAPTION 'C~lear All' ;
      SIZE 10, 1.1 ;
      FONT '8.MS Sans Serif' ;
      ACTION {|| AEVAL(aFields, {|x,i| oListBox:setData(i, .F.)}), ;
                 DC_VarFromListBox(oListBox)} ;
      RELATIVE oListBox

   DCREAD GUI ;
     TITLE 'Select Multiple' ;
     FIT ;
     ADDBUTTONS ;
     MODAL

   // DC_MsgBox(cField)

RETURN cField


I need to remove this

Code:
   @ 0, 17 DCPUSHBUTTON ;
      CAPTION '~Mark All' ;
      SIZE 10, 1.1 ;
      FONT '8.MS Sans Serif' ;
      ACTION {|| AEVAL(aFields, {|x,i| oListBox:setData(i, .T.)}), ;
                 DC_VarFromListBox(oListBox)} ;
      RELATIVE oListBox

   @ 1.5, 17 DCPUSHBUTTON ;
      CAPTION 'C~lear All' ;
      SIZE 10, 1.1 ;
      FONT '8.MS Sans Serif' ;
      ACTION {|| AEVAL(aFields, {|x,i| oListBox:setData(i, .F.)}), ;
                 DC_VarFromListBox(oListBox)} ;
      RELATIVE oListBox


But, I need to do this action every time I click on one Item.
Clear all
Select the Item clicked.

Code:
      ACTION {|| AEVAL(aFields, {|x,i| oListBox:setData(i, .F.)}), ;
                 DC_VarFromListBox(oListBox)} ;


Thanks for your help.


Top
 Profile  
 
PostPosted: Fri Oct 14, 2016 7:52 am 
Offline
Site Admin
User avatar

Joined: Wed Jan 27, 2010 6:58 pm
Posts: 4125
Location: Boise, Idaho USA
Compile and run the below code.
I think this is what you want.

Code:
#INCLUDE "dcdialog.CH"

FUNCTION Main()

LOCAL aItems[0], aDir, i

aDir := Directory()

FOR i := 1 TO Len(aDir)
  AAdd( aItems, aDir[i,1] )
NEXT

RETURN sListBox( aItems )

PROC appsys ; RETURN

FUNCTION sLISTBOX(aITEMS)

   LOCAL GetList := {}, aFields:={}, cField:={}
   LOCAL oListBox, bClearAll

   bClearAll := {|| AEVAL(aFields, {|x,i| oListBox:setData(i, .F.)}), ;
                 DC_VarFromListBox(oListBox)}

   aFields := aITEMS

   @ 0,0 DCLISTBOX cField LIST aFields ;
      FONT "10.Courier" ;
      SIZE 25,10 ;
      OBJECT oListBox ;
      MARKMODE XBPLISTBOX_MM_SINGLE

   DCREAD GUI ;
     TITLE 'Select Multiple' ;
     FIT ;
     ADDBUTTONS ;
     MODAL ;

RETURN cField

_________________
The eXpress train is coming - and it has more cars.


Top
 Profile  
 
PostPosted: Fri Oct 14, 2016 7:08 pm 
Offline
User avatar

Joined: Tue Jul 28, 2015 5:15 am
Posts: 94
Wonderfull

I added this line to THE LISTBOX.

Code:
MARKMODE XBPLISTBOX_MM_SINGLE


Works perfectly.

Thank you!


Top
 Profile  
 
PostPosted: Fri Oct 14, 2016 7:20 pm 
Offline
User avatar

Joined: Tue Jul 28, 2015 5:15 am
Posts: 94
Here it is

The code should look like this.

Code:
   @ 0,0 DCLISTBOX cField LIST aFields ;
      FONT "10.Courier" ;
      SIZE 15,10 ;
      OBJECT oListBox ;
      MARKMODE XBPLISTBOX_MM_SINGLE
     
      // MARKMODE XBPLISTBOX_MM_SINGLE
      // MARKMODE XBPLISTBOX_MM_MULTIPLE
      // MARKMODE XBPLISTBOX_MM_EXTENDED
      // SELECT {2,4,5,6,7}


By default, it is the Multiple.

SINGLE allow you to click only one
MULTIPLE allow you to click on more than one DEFAULT
EXTENDED allow you to click on more then one, Using Click + Shift Click select many.

Thank you Roger.
You made my day.

Very happy!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group