Table of Contents

Article

Example: Integrating a ListView within an application

The techniques described in this article can also apply to other controls.

A common situation faced by Pega® Robotic Automation 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 Robotic Automation 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, you could use the this object of the Windows form to synchronize events with the UI thread. Doing this lets the Robotic Automation 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, Robotic Automation 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.
    <strong>dataGridView1.DataSource = m_TaskManager.listView.DataTable</strong>;

    // 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 Robotic Automation 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.

Pega Robotic Automation Studio version Built by using version Download link
7.1 7.1.26 ListView Example 7.1
8.0 8.0.1037 ListView Example 8.0

Published January 3, 2017 — Updated March 8, 2018


50% found this useful

Have a question? Get answers now.

Visit the Pega Support Community to ask questions, engage in discussions, and help others.