Selecting an Item in the FlexDataGrid Control

You can select an item in the FlexDataGrid control using the following procedures.

If you know the index value of the FlexDataGrid item, use the SelectIndex method.

For example, type FlexDataGrid.SelectIndex(1)

  1. If you know the content value of the FlexDataGrid item, use the Select method.
  2. Identify the row that you want to select with the required formatted string. Items must be separated by a pipe (“ | ”). At least one Item must be enclosed by two stars (“*”). This identifies the item where the click will be performed.

    The syntax is: FlexDataGrid.Select(“*Item1* | Item2 | Item3”)

The following example selects an item using the Select method (randomly).

[ ] LIST OF LIST OF STRING  allVisibleItems
[ ] window dataGrid = AdobeFlashPlayer9.FlexApplication0.Index0.Index1.SwfLoader.ControlsSimpleDataGridSwf.DataGridControlExample.Dg
[ ] 
[ ] // lets get all currently visible items
[ ] allVisibleItems = dataGrid.GetValues(dataGrid.firstVisibleRow, dataGrid.lastVisibleRow)
[ ] 
[ ] // pick a random element that we want to select
[ ] integer randomRow = RandInt(dataGrid.firstVisibleRow, dataGrid.lastVisibleRow)
[ ] LIST OF STRING randomRowItems = allVisibleItems[randomRow]
[ ] print("This is the row we want to select: {randomRow}")
[ ] 
[ ] // now lets construct the string we need for the select method
[ ] STRING selectString
[ ] STRING itemText
[ ] INTEGER col = 0
[-] for each itemText in randomRowItems
[-] if col == 0
[ ] selectString = "*{itemText}*"
[-] else
[ ] selectString = selectString + " | {itemText}"
[ ] col++
[ ] 
[ ] // now lets select the item
[ ] print("We will select {selectString}")
[ ] dataGrid.Select(selectString)