Skip to main content


         This documentation site is for previous versions. Visit our new documentation site for current releases.      
 

This content has been archived and is no longer being updated.

Links may not function; however, this content may be relevant to outdated versions of the product.

Robotic Automation example: Integrating a ListView within an application

Updated on February 1, 2023
Note: The techniques described in this article can also apply to other controls.

A common situation faced by Pega Robot Studio developers is how to get information from a ListView control in some application. This example uses the Task Manager application that comes with Windows as an example and shows how to read information from that application then manipulate it in your own custom application.

The main points of using Robot Studio with .NET that are demonstrated in this article include the following topics:

The following example includes a Windows form that copies information from the Task Manager:

Sample ListView window

The Task Manager is a standard Windows application.

Windows Task Manager window

Starting the Task Manager application

There is an important change in how the application is started compared to the earlier project.

if ( !m_TaskManager.IsRunning )
{
    m_TaskManager.Start();
}

The Start method can take a parameter that provides a synchronization object so that events coming in on other threads are automatically assembled in the UI thread. However, because you are not handling events from the Task Manager application, you do not need to perform this action. If you were, use the this object of the Windows form to synchronize events with the UI thread. Doing this lets the Robot Studio adapters automatically assemble their events to your user interface so you do not have to.

You only need to do this for adapters that you handle events from and the event handlers that modify user interface items. Because neither of those conditions are true, use the Start method.

Working with the ListView control

There is nothing to show outside of how to start the Task Manager application. This is because after it is started, Robot Studio works with the ListView as though it was an object in your C# project. Some of the methods are different from a standard ListView, and some are more powerful than what you get from .NET.

For instance, in the following routine, you see code that uses the m_TaskManager adapter to assign a DataTable to the dataGridView that you are using on the Windows form. That single line of code causes the information to be copied from one application to the other. The rest of the code then writes a message that indicates how many rows and columns there are:

///
/// This automation sends the contents of the ListView from
/// the Processes tab of the Task Manager
/// to a DataGrid on a Windows Form.
/// The automation also determines a count of the total number
/// of rows returned for the ListView and generates
/// a message if no rows are returned. 
/// The number of rows is displayed on the Win Form.
/// 
private void SendListViewtoDataGrid()
{
    // Populates the Data Grid View with data from Task Manager.
    dataGridView1.DataSource = m_TaskManager.listView.DataTable;

    // Update windows form based on number of rows returned.
    int numRows = m_TaskManager.listView.DataTable.Rows.Count;
    if ( numRows > 0 )
    {
        label8.Text = "The Process Grid contains " + numRows + " rows";
    }            
    else          
    {             
        label8.Text = "Task Manager returned No Processes";
    }
}

Likewise, the other parts of the code search for items in the ListView to read a line of text from the other application, such as the following line:

txtRowDataResults.Text = m_TaskManager.listView.GetItemFullText(rowIndex,numColumns);

When you run the application, you should also select a different tab in the Task Manager and then refresh the data grid on the C# application. The Robot Studio adapter reads the data from the ListView and not directly from the screen.

After you have created the adapter to the application, using the controls in the adapter is similar to how you use objects in any other .NET application.

Robot Studio versionBuilt by using versionDownload link
8.08.0.1037ListView Example 8.0
8.0 SP18.0.2037ListView Example 8.0 SP1
  • Previous topic Robotic Automation example: Handling cancelable events in .NET
  • Next topic Robotic Automation example: Rewriting the HTML of a web control

Have a question? Get answers now.

Visit the Support Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega.com is not optimized for Internet Explorer. For the optimal experience, please use:

Close Deprecation Notice
Contact us