Created On:  09 May 2012
 
How do you verify if an item exists in a Flex Spark dropdown list / combo box / items list / menu?

You can get a list of the items in a Spark dropdown list / combo box / item list / menu using the GetValues() method but unfortunately GetValues() is undocumented. The following function will give you a TRUE or FALSE return depending on whether the item is listed.

[-] boolean GetSparkItem(window wWin, string sCompare)
 [ ] int i=0
 [ ] boolean bPass=false
 [ ] list of anytype laText
 [ ] string sItemName=""
 [ ]
 [ ] bPass=bOpen
 [-] do
  [ ] wWin.Open() // cbo, ddl or menu must be exposed before being read
 [-] except
  [ ] // Error bucket if the list does not require to be opened - do nothing 
 [ ]
 [ ] // Get the number of items in the list
 [-] do
  [ ] i=wWin.GetItemsCount()    // dll, cbo, itemslist
 [-] except
  [ ] i=wWin.numRows            // menu
 [ ]
 [ ] laText=wWin.GetValues(0,i)
 [-] for(i=1;i<=wWin.GetItemsCount();i++)
  [ ] // Cast the laItem to a string
  [ ] sItemName=[string]laText
  [ ] // Strip the braces
  [ ] sItemName=right(sItemName,len(sItemName)-1)
  [ ] sItemName=left(sItemName,len(sItemName)-1)
  [ ]
  [-] if (MatchStr (sCompare, sItemName))
   [ ] // A match has been found so return true
   [ ] bPass=true
   [ ] return bPass
 [ ] // No match found
 [ ]  return bPass

Call the function as follows:-

[ ] boolean bPass=FALSE
[ ] bPass=GetSparkItem(SparkObject,"item to be found")

Many Spark list objects have a GetValues() method, so the function can be extended for other Sparks list objects by identifying which method is needed to read the number of items in the list. If the method is not listed in the function then add it to the 'Get the number of items in the list' do...except construct.

 
Incidents #2572130, #2573935