Listbox: Have no Items Selected

Started by steptoe, Mon 02/04/2012 16:48:47

Previous topic - Next topic

steptoe

Hi

I'm checking through the manual/forums to see if I can use a ListBox string name rather than ID.

It seems first item added is 0 then 1 then 2 etc etc

Obviously I need to check which item has been selected before running events for that item.

At the moment an event will run if ID 0 is selected from Listbox irrespective of what it is..

Code: ags

ListBox1.AddItem("Key");



EDIT


Global takes this but goes to else (having clicked 'Key' in the ListBox)

Code: ags

function ListBox1_OnSelectionChanged(GUIControl *control)
{
  if(ListBox1.ID==Key)
  { Display("Perhaps you should find out who has had the key lately");
  } else
  { Display("Sorry no go!");
  }
  }




I need to check that "Key" has been selected from ListBox before events are run.

Could someone give me a hand please?


Khris

Listbox.ID is the number of the listbox in the GUI's .Controls array. For instance, if you added the listbox to a blank GUI, the ID is 0.

You're looking for .SelectedIndex.

Code: ags
  String itemname = ListBox1.Items[ListBox1.SelectedIndex];

  if (itemname == "Key") { 
    ...
  }

steptoe

Thank you so much Khris...

Great help to me

steptoe



steptoe

#3
EDIT....
Added a dummy blank item and now seems to work as expected...



-------------------------------------------------------

I am trying to NOT have any of the Listbox Items actually selected until you have actually selected any of them.  Khris, the code you gave me works up to that point.

What  I am working on is that after selecting an item in the ListBox is to have the mouse change graphic and use that on characters to revoke that particular subject conversation. Almost Active Inventory like.

In the manual it states: -1 to remove the highlight but obviously I may/may not need some kind of blind item?

Meanwhile I will keep reading the manual plus any help here will hopefully guide me through this.

cheers

SMF spam blocked by CleanTalk