[Gambas-user] Selection from a list

Aleksandrs Livshics aleks.l at ...1865...
Thu Sep 3 15:10:05 CEST 2009


Thanks to everyone. I just had some syntax problem  which you have explained.
Alex

On Thursday 03 September 2009 14:50:53 Dimitris Anogiatis wrote:
> Alex,
>
> Setting the mode to Multiple does allow that...
>
> if for example you have 6 items on your listbox
> if you execute these 2 lines the 1st & the 4th item
> will be selected
>
> listbox1[0].Selected = TRUE
> listbox1[3].Selected = TRUE
>
> (in Gambas 2.14 on my Debian Lenny it works as described)
>
> If the user wants to change the selection, in order for them
> not to lose the previous selection, they have to press CTRL
> before they click on a new item or deselect one of the already
> selected.
>
> Now to check which items are selected on your listbox... Unless
> I'm also missing some other easier way... I would suggest a function like
> this
>
> PUBLIC FUNCTION multipleSelections(targetLB AS ListBox) AS String
>   DIM targetCount AS Integer
>   DIM foundSelected AS Integer
>   DIM Res AS String
>
>   targetCount = 0
>   foundSelected = 0
>   DO WHILE targetCount < targetLB.Count
>    IF targetLB[targetCount].selected = TRUE THEN
>     Res &= targetLB[targetCount].Text & "|"
>     INC foundSelected
>    ENDIF
>   INC targetCount
>   LOOP
>
> IF foundSelected = 0 THEN
>     RETURN "Nothing found"
>   ELSE
>     RETURN Left(Res, Len(Res) - 1)
> ENDIF
>
> END
>
>
> You could use it like this:
>
> Print multipleSelections(listbox1)
>
> and as a result you would get this
>
> Item 1|Item 4
>
> (that's the text of the selected items)
>
> if you want their indices you could modify it so you could
> get the selected item indices in the same way
>
> I hope this helps
>
> Regards,
> Dimitris
>
> On Thu, Sep 3, 2009 at 5:04 AM, Aleksandrs Livshics <aleks.l at ...1865...> wrote:
> > Hallo to everyone.
> > Can anyone tell me whether a ListBox can be used to
> > display a list with several items preselected and then
> > to allow a user to change some part of this selection?
> > I think mode "multiple" must allow to do this. However
> > I do not understand how to preselect more than one item
> > and how to get the indexes of the finally selected items,
> > if there are more then one of them.
> > My difficulty is due to the fact that if I want to set some
> > item as "selected=TRUE" I have to make it "current" by
> > specifying the "index". But by doing this I change the status
> > of the item which was "current" before... It does not remain
> > "selected=TRUE" , does it?
> > I probably do not understand something.
> > Alex
> >
> >
> > -------------------------------------------------------------------------
> >----- Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> > 30-Day trial. Simplify your report design, integration and deployment -
> > and focus on
> > what you do best, core application coding. Discover what's new with
> > Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
>
> ---------------------------------------------------------------------------
>--- Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> 30-Day trial. Simplify your report design, integration and deployment - and
> focus on what you do best, core application coding. Discover what's new
> with Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user





More information about the User mailing list