Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: ComboBox: retrieve 'index' of current choice?  (Read 19218 times)
Bryce S.
Posts: 52


« on: February 25, 2008, 12:17:45 am »

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.
.
Posts: 14


« Reply #1 on: February 25, 2008, 12:44:58 am »

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
  1. FUNCTION comboBox_getTextByItemName(fieldname, itemname)
  2. DEFINE fieldname STRING
  3. DEFINE itemname STRING
  4. DEFINE cb ui.ComboBox
  5.  
  6.   LET cb = ui.ComboBox.forName(fieldname)
  7.   # add some error handling here if cb null
  8.  
  9.   FOR i = 1 TO cb.getItemCount()
  10.     IF cb.getItemName(i) = itemname THEN
  11.         RETURN cb.getItemText(i)
  12.      END IF
  13.   END FOR
  14.   # add some error handling to cater for case where name not found
  15.   RETURN ""
  16. END FUNCTION

Hope that helps,

Reuben

   
Bryce S.
Posts: 52


« Reply #2 on: February 25, 2008, 01:26:58 am »

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.
Four Js
Posts: 545


« Reply #3 on: February 25, 2008, 09:15:37 am »

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.
Posts: 52


« Reply #4 on: March 02, 2008, 09:14:20 pm »

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.
Four Js
Posts: 45


« Reply #5 on: March 03, 2008, 05:48:10 pm »

Bryce,

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

Best regards,
Bernard 
Sebastien F.
Four Js
Posts: 545


« Reply #6 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
Bryce S.
Posts: 52


« Reply #7 on: March 04, 2008, 08:41:31 pm »


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

Very good, I like it.
Thanks, Bryce Stenberg.
Paul S.
Posts: 45


« Reply #8 on: March 20, 2008, 12:17:01 pm »

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

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
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines