ComboBox: retrieve 'index' of current choice?

Started by Bryce S., February 25, 2008, 12:17:45 AM

Previous topic - Next topic

Bryce S.

Hi,

Anyone know what function to call to get the 'index' of the currently chosen item in a ComboBox?

ComboBox using addItem adds a 'Name' string and a 'Text' string.
The first 'Name' value is returned to the program variable.
I now want to grab the 'Text' that went with that choice.
But how do I get it without knowing the index of the choice?
The only function I can find to get the text is 'getItemText' which requires an integer 'index' parameter.
I know I could write something to run through the form (or dom tree?) and find it, but I think it should be simpler than that, like maybe a function called getCurrentIndex() or something.

example:

CALL cb.clear()
CALL cb.addItem("O","Open Driver")
CALL cb.addItem("T","Trials Driver")
CALL cb.addItem("V","Overseas Junior Driver")
CALL cb.addItem("J","Junior Driver")

if user chooses 3rd option above the program variable gets 'V', I am after an easy retreive of associated text string value "Overseas Junior Driver" to display and use elsewhere.

Thanks,
  Bryce Stenberg
  Harness Racing New Zealand Inc.

.

Bryce,

Can't think of one of the top of my head but using ui.ComboBox.forName and other ui.ComboBox methods  it should be relatively simple to write a library function that returns the value you are after

Untested but something like...

Code (genero) Select
FUNCTION comboBox_getTextByItemName(fieldname, itemname)
DEFINE fieldname STRING
DEFINE itemname STRING
DEFINE cb ui.ComboBox

   LET cb = ui.ComboBox.forName(fieldname)
   # add some error handling here if cb null

   FOR i = 1 TO cb.getItemCount()
     IF cb.getItemName(i) = itemname THEN
         RETURN cb.getItemText(i)
      END IF
   END FOR
   # add some error handling to cater for case where name not found
   RETURN ""
END FUNCTION


Hope that helps,

Reuben

   

Bryce S.

Thanks Reuben, I write something like that.  I still think getting the current index (or the current text string) should be one of the combobox's methods however.

Regards, Bryce.

Sebastien F.

Bryce,

Actually there is no "current index" or "current item" in a combobox drop down list:
What is relevant is the current value of the field.
This value could be used to search the index of the item in the list.

So instead of a "getCurrentItem" or "getCurrentIndex" method, I would prefer something like:

  ui.ComboBox.getIndexOf("current key value") returning integer

Seb

Bryce S.

Hi,

Just to second Sebastien's idea - that would be ideal to have a 'getIndexOf' method, would allow one to work with the already available methods which require an index value.

FourJs - can this be added as a feature request?

Regards,
  Bryce Stenberg.

Bernard M.

Bryce,

This has been registered as new feature request #Fz.2475.

Best regards,
Bernard 

Sebastien F.

FYI:

After internal discussion, we will probably do this:

    ui.ComboBox.getItemTextByName( name string ) returning string

Since the item name must be unique, we think this makes more sense as:

    ui.ComboBox.getIndexOf( name string ) returning integer

Any comment is welcome.

Seb

Bryce S.


>    ui.ComboBox.getItemTextByName( name string ) returning string

Very good, I like it.
Thanks, Bryce Stenberg.

Paul S.

I see this has been added to the 2.11 Online Docs. in the New Features Section.

When will 2.11 be ready for beta or will 2.11 become 2.20?

Paul

Quote from: Sebastien FLAESCH on March 04, 2008, 11:30:03 AM
FYI:

After internal discussion, we will probably do this:

    ui.ComboBox.getItemTextByName( name string ) returning string

Since the item name must be unique, we think this makes more sense as:

    ui.ComboBox.getIndexOf( name string ) returning integer

Any comment is welcome.

Seb