Understanding Infragistic controls: CheckBox, RadioList, ListView, ComboBox

TestComplete correctly records actions for standard .NET controls, but it only records mouse clicks for Infragistic controls in TestComplete 5. To work around this, you just need to search for the appropriate methods and/or properties and use them in your scripts.

CheckBox

For checkboxes, you can use the Checked property to get the value and the set_Checked() method to set the checkbox's state.

Here is an example:

If for some reason you need to perform a mouse click for checking or unchecking a checkbox (e.g. to emulate user click) you can use the following sample:

This function clicks on a checkbox if its state is different from the needed state, or posts a message that the checkbox has already been checked or unchecked.

RadioList

To retrieve the currently checked item from a RadioList, you can use the CheckedItem property or the corresponding get_CheckedItem() method to get the item's text and use CheckedIndex to get it's index number. To set an item in the RadioList we can use the set_CheckedIndex() or set_CheckedItem() methods. The set_CheckedIndex() method selects an item by its number and is not dependant on the text. The set_CheckedItem() method is useful if you don't know the item's index, but know its text.

Here is an example of how to retrieve the selected item's data:

Now you need to create a function that will select an item. I suggest making it possible to select an item by both its index and text. To do this we just need to check the item parameter type and call the appropriate method. To check the parameter type we can use the "type of" operator.

Below is an example of using this function.

ComboBox

Out of all four controls, the ComboBox is the easiest to work with, since you don't need to create new functions. To read the current value in a ComboBox, use the Text property, and to select an item in the ComboBox, use the set_SelectedText() method.

Here is a simple script that selects an item and then checks if the correct item has been selected.

ListView

The Infragistic List View is more complicated than the other controls. First, it has five possible view types: Details, Icons, List, Tiles and Thumbnails. Second, there may be more than one item selected. Third, its Items property doesn't have the Bounds property, so we will need to find another way to get the item's screen coordinates in order to perform a click.

To work with the List View, you need to create three basic functions: getting selected items, selecting several items and clicking an item.

To get the selected items you need to use the SelectedItems property. Function returns a string with all of the selected items separated with the "|" (pipe) symbol. You need to iterate through all of the selected items and add them to the returning string. After the last selected item is added you need to return the result string skipping the last "|" symbol.

Here is the code sample:

To select several items, use the SelectedItems property and the Clear() and Add() methods. The Clear() method, clears the current selection. The Add(), adds the new selected items. Items to be selected are separated with the "|" symbol. 

Below is an illustration of this function.

The Update() method is optional after its usage control is updated to show the selected items on screen. Otherwise, the items are selected, but the user won't see them.

Finally you need to create a function to click on the specified item in the ListView. As I said before, the Items property does not have the Bounds property. However, you can use the UIElement.ClipRect property to get the coordinates of the item. Also, you should bring an item into view before clicking on it.

Here is the code sample to click an item in the Infragistic list view:

When using this function for different ListView types, you will find that it works perfectly with Details, Icons, Tiles and Thumbnails, but may fail with the List type. This occurs because the item in the ListView List type should be clicked on within the text area. So, if of the view's list width is more than twice as wide as the text's, the wide item won't be clicked on, because our function clicks on the center of the item.

You can modify the function to always click on the specific X coordinate (e.g. 20), but we only need it for one type of ListView. Also hard coding coordinates isn't a good idea. You can use the TextSizeList property which contains the text's width. Also, you need the ListView View property to get the current view type.

This function works correctly for all view types.

Here is the sample function that uses all of the created functions.

You can download the sample application from the link below:

Infragistic Samples (zip, 6 Kb)


Close

Add a little SmartBear to your life

Stay on top of your Software game with the latest developer tips, best practices and news, delivered straight to your inbox

By submitting this form, you agree to our
Terms of Use and Privacy Policy

Thanks for Subscribing

Keep an eye on your inbox for more great content.

Continue Reading