#1 2015-06-16 22:38:14

Registered: 2015-04-21
Posts: 64

MultiSelect control - index of SelItem(s)

my problem is to get the ItemIndex of a selection in a MultiSelect control. I know it is a "Multi"Select control, but I use it because it is much more comprehensible for the user. I fill the Selector.Items out of a database and at a click on 1 item I have to get the index number of the selected item.

I tried this code, but it doesn´t work because recno is always -1:

SetVar "find" "[Select3.SelItems]" "String"
ArrayIndexOf "Select3.Items" "[find]" "recno"

Do I misunderstand  ArrayIndexOf ? Thanks for your help.

kind regards,


#2 2015-06-16 23:02:48

From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,717

Re: MultiSelect control - index of SelItem(s)

Hello Walter,

In a Multiselect control we do not have an "ItemIndex" variable like in the Select control. What we have is an "Items" variable and an "SelItems" variable. Since "SelItems" variable contains the selected items, if a user choose one item, then the "SelItems" variable contains one element with the selected item value.

From that value we can use the ArrayIndexOf action over the select items array in order to get the selected item index. Take a look at the bellow code, which you can put in a "Change" event of a Multiselect control (which contains a few items):

// Get what items the user select
ArrayLength "[Select1.SelItems]" "[SelectedLength]"

// If the user select more than one item, get only the first item
If "[SelectedLength]" ">" "1"

  // Get the first selected item
  ArrayGetItem "[Select1.SelItems]" "0" "[SelectedItem]"   
  // Clera the selected items array
  ArrayClear "[Select1.SelItems]"
  // Add the selected item to the array
  ArrayPush "[Select1.SelItems]" "[SelectedItem]"

// Get the user selected item
ArrayGetItem "[Select1.SelItems]" "0" "[SelectedItem]"

// Get the item index of the selected item
ArrayIndexOf "[Select1.Items]" "[SelectedItem]" "[ItemIndex]"

// Show the selected item index
AlertBox "Selected item index is: [ItemIndex]" "info"

Note that in the above code we also check the user select more than one item. If so, we take the first of the selected items and omit all others. If you have any other doubt do not hesitate to post here Walter.


Board footer

Powered by FluxBB

Copyright ©2018 DecSoft. All rights reserved.