So what you'll need here is the following.
1) A list of items you want to click (I use a string array).
2) The listbox object .
3) The scroll bar object.
Once you have those you can loop through your items you want to click using a foreach. If this is your first item in the list, do a regular click else for each successive item to a control click.
The following is code I use to multi select values in a grid but you can change it just a bit to do multi select in a list box. Pay attention to the click section at the end for an idea of using the control key for multi select.
- Code: Select all
public static int MultipleClickCellsInTable(Ranorex.Form RanorexFormName, Ranorex.Table HDTable, string[] strCellsTEXTToClick)
{
try
{
HDTable.EnsureVisible();
Ranorex.ScrollBar HDScrollBar = null;
Ranorex.Button PageUp = null;
Ranorex.Button PageDown = null;
Ranorex.Button LineDown = null;
RanorexFormName.Activate();
//Get Parent Element
Ranorex.Core.Element parentElement = HDTable.Element.Parent;
//Check for the Vertical Scroll bar
try
{
HDScrollBar = parentElement.FindSingle(".//element[@controltypename='VCrkScrollBar']/scrollbar[@accessiblename='scroll bar']", 30000);
PageUp = HDScrollBar.FindSingle(".//button[@accessiblename='Page Up']", 30000);
PageDown = HDScrollBar.FindSingle(".//button[@accessiblename='Page Down']", 30000);
LineDown = HDScrollBar.FindSingle(".//button[@accessiblename='Line Down']", 30000);
//Scroll to Top
while (HDScrollBar.Value != 0)
{
PageUp.Click();
}
}
catch (RanorexException e)
{
//No vertical Scroll Bar
}
RanorexFormName.Activate();
int intItemCount = 0;
foreach (string celltext in strCellsTEXTToClick)
{
//Search for the Resource Requested
Ranorex.Cell RanorexCell = TableCellReturnCellObject(HDTable, celltext, "Resource Code");
if (RanorexCell == null)
{
Report.Failure("Requested Resourece: " + celltext + " was not found in the Table.");
return -1;
}
//Verify the Cell is Visible
if (RanorexCell.Visible.ToString() == "False")
{
while (HDScrollBar.Value != 0)
{
PageUp.Click();
}
while (RanorexCell.Visible.ToString() == "False")
{
PageDown.Click();
Thread.Sleep(500);
}
}
//Click the Cell
Report.Debug("Left Clicking cell " + RanorexCell.Element.GetAttributeValue("AccessibleName").ToString());
if (intItemCount > 0)
{
Keyboard.Press("{ControlKey DOWN}");
RanorexCell.Click(Location.UpperCenter);
Keyboard.Press("{ControlKey UP}");
}
else
{
RanorexCell.Click(Location.UpperCenter);
}
intItemCount++;
}
return 0;
}
catch (RanorexException e)
{
return -1;
}
}
[/code]
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...