[Gambas-user] listbox display selected item
Stephen Bungay
sbungay at ...981...
Thu Jul 23 18:09:58 CEST 2009
Good work-around Dimitris.
Dimitris Anogiatis wrote:
> JY, I think I got it working the way you want it...
>
> try my example with a new project with a listview and a timer. Set the timer
> for 10 miliseconds and enable it
>
> and paste this code in the class
>
> -----------------------------------------------------------------------------------------------------------------------------------------------------
>
> ' Gambas class file
>
> PUBLIC SUB _new()
>
> END
>
> PUBLIC SUB Form_Open()
> Listview1.Add("Blah", "Hi there")
> Listview1.Add("Blah2", "How are you")
> Listview1.Add("Blah3", "I'm good")
> Listview1.Add("Blah4", "How about you?")
>
> END
>
> PUBLIC SUB chooseSub(choice AS String)
>
> SELECT CASE choice
> CASE "Blah"
> PRINT ("Key is Blah")
> CASE "Blah2"
> PRINT ("Key is Blah2")
> CASE "Blah3"
> PRINT ("Key is Blah3")
> CASE "Blah4"
> PRINT ("Key is Blah4")
> CASE ELSE
> END SELECT
>
> END
>
> PUBLIC SUB ListView1_Click()
>
> chooseSub(Listview1.Item.Key)
>
> END
>
> PUBLIC SUB Timer1_Timer()
>
> 'Listview1.Find(Mouse.ScreenX - fmain.ScreenX - Listview1.Left,
> Mouse.ScreenY - Fmain.ScreenY - Listview1.Top)
> IF Listview1.Count > 0 THEN
> SELECT CASE Listview1.Find(Mouse.ScreenX - Fmain.ScreenX -
> Listview1.Left, Mouse.ScreenY - Fmain.ScreenY - Listview1.Top)
> CASE FALSE
> Listview1[getKeyFromPosition(Listview1, (Mouse.ScreenY -
> Fmain.ScreenY - Listview1.Top) \ 25)].selected = TRUE
>
> CASE ELSE
> END SELECT
> ENDIF
>
> END
>
> PUBLIC FUNCTION getKeyFromPosition(lv AS ListView, pos AS Integer) AS String
> DIM iterator AS Integer
> DIM tmpCount AS Integer
>
> DIM res AS String
>
> IF pos <= 0 THEN tmpCount = 0
> IF pos >= lv.Count THEN
> tmpCount = lv.Count - 1
> ELSE
> tmpCount = pos
> ENDIF
>
> lv.MoveFirst
>
> FOR iterator = 0 TO tmpCount - 1
> lv.MoveNext
> NEXT
>
> res = lv.Item.Key
>
> RETURN res
> END
>
> -----------------------------------------------------------------------------------------------------------------------------------------------------
>
> be careful of all the events firing and the code executing... but I think I
> got it as close to what you want it to do, as possible
>
> hope this helps in your project
>
> Keep up the good work
>
> Regards,
> Dimitris
>
>
> On Wed, Jul 22, 2009 at 11:47 PM, Jean-Yves F. Barbier <12ukwn at ...626...>wrote:
>
>> Dimitris Anogiatis a écrit :
>>> JY,to select a specific item in a listview you have to provide the item's
>>> key like this
>>>
>>> Listview1["Blah"].Selected = True
>>>
>>> if you want to automatically select the first item that is on the
>> listview
>>> you try this
>>>
>>> IF Listview1.Count > 0 THEN
>>> Listview1.MoveFirst
>>> Listview1.Item.Selected = True
>>> ENDIF
>> Not this Time, Dimitri.
>> I'm searching a behaviour as Stephen told about.
>> In fact I expected the selection bar to automatically move, such as in
>> a ComboBox (Benoît, why ListBox & ListView don't act alike ComboBox??)
>>
>> I guess we should be more tyrannical toward Benoît, so he won't loose time
>> scratching his wiki's root, nor watching TV neither sleeping ;-)
>>
>> JY
>> --
>> I read the newspaper avidly. It is my one form of continuous fiction.
>> -- Aneurin Bevan
>>
>>
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> Gambas-user mailing list
>> Gambas-user at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
> ------------------------------------------------------------------------------
> _______________________________________________
> 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