[Expand]General Information/viewarticle/63445/
 [Expand]Using Help System/viewarticle/55799/
 [Expand]Getting Started Tutorial/viewarticle/56246/
 [Expand]Using TestComplete/viewarticle/57875/
 [Expand]Testing Types/viewarticle/62721/
 [Expand]Applications Testing/viewarticle/62606/
 [Collapse]Working With Application Objects and Controls/viewarticle/55815/
  [Expand]General Information/viewarticle/63362/
  [Expand]Common Tasks/viewarticle/56267/
  [Expand]Simulating User Actions/viewarticle/56262/
  [Collapse]Object-Specific Tasks/viewarticle/63386/
   [Expand]Working With Standard Windows Controls/viewarticle/61593/
   [Expand]Working With Android Controls/viewarticle/58141/
   [Expand]Working With iOS Controls/viewarticle/63575/
   [Collapse]Working With Grids/viewarticle/55282/
     Working With Grids - Basic Concepts/viewarticle/61980/
     Common Operations for Grids/viewarticle/62006/
    [Expand]Borland TDBGrid/viewarticle/63214/
    [Expand]Developer Express QuantumGrid/viewarticle/60614/
    [Collapse]Developer Express XtraGrid/viewarticle/60655/
      Working With Developer Express XtraGrid - Overview/viewarticle/60655/
      Accessing Views in Developer Express XtraGrid/viewarticle/63227/
      Searching for Records in Developer Express XtraGrid/viewarticle/63234/
      Selecting Cells in Developer Express XtraGrid/viewarticle/63229/
      Getting the Focused Row, Column and Cell in Developer Express XtraGrid/viewarticle/63237/
      Activating and Closing In-place Editors in Developer Express XtraGrid/viewarticle/63230/
      Obtaining and Setting Cell Values in Developer Express XtraGrid/viewarticle/63231/
      Working With Specific In-place Editors in Developer Express XtraGrid/viewarticle/63232/
      Copying and Pasting Cell Values in Developer Express XtraGrid/viewarticle/61983/
      Selecting Multiple Rows and Cards in Developer Express XtraGrid/viewarticle/63233/
      Obtaining Selected Records in Developer Express XtraGrid/viewarticle/63235/
      Iterating Through Rows and Cards in Developer Express XtraGrid/viewarticle/63228/
      Sorting Data in Developer Express XtraGrid/viewarticle/63236/
      Expanding and Collapsing Rows in Developer Express XtraGrid/viewarticle/61997/
    [Expand]Microsoft DataGrid/viewarticle/63259/
    [Expand]Microsoft DataGridView/viewarticle/63250/
    [Expand]Microsoft PropertyGrid/viewarticle/63261/
    [Expand]Infragistics UltraWebGrid/viewarticle/63309/
    [Expand]Infragistics WinGrid/viewarticle/63241/
    [Expand]Java Swing JTable/viewarticle/63315/
    [Expand]Syncfusion GridControl/viewarticle/63291/
    [Expand]Syncfusion GridDataBoundGrid/viewarticle/63268/
    [Expand]Syncfusion GridGroupingControl/viewarticle/63283/
    Working With Open File and Save File Dialogs/viewarticle/55492/
    Testing Modal Windows/viewarticle/55107/
    Working With Ribbon Command Bars in Windows 7 Applications/viewarticle/63385/
    Working With XtraBars Controls/viewarticle/60549/
    Working With .NET ErrorProvider/viewarticle/62759/
 [Expand]Samples and Tutorials/viewarticle/56239/
 [Expand]Other Tools That Help You Test Better/viewarticle/63442/
 [Expand]TestComplete Licensing Guide/viewarticle/63451/
Updated: 3/11/2014 Applies To: TestComplete 10 Rating: AverageAverageAverageAverageAverage 3 vote(s) Click to rate: PoorNot badAverageGoodExcellent
Working With Developer Express XtraGrid Select language for code samples Select language for code samples

Expanding and Collapsing Rows in Developer Express XtraGrid

The XtraGrid control supports hierarchical data representation. If the grid displays data of multiple nested data tables, then each data row can have child rows containing data associated with this row. To view the child data, the user needs to expand its parent row. The grid data can also be grouped by one or several columns, so the individual rows are organized into groups. This topic explains how you can expand and collapse rows and groups in the XtraGrid control from your test scripts:

To perform these actions, TestComplete should have access to internal objects, properties and methods of the XtraGrid control. For this purpose, the .NET Application Support and Developer Express Control Support plug-ins must be installed and enabled. The latter lets you work with the XtraGrid control using methods and properties of the DevExpressXtraGrid object. Without this plug-in, you will not be able to work with XtraGrid controls using their internal methods and properties.

When testing Developer Express XtraGrid controls, use specific methods and properties of the corresponding DevExpressXtraGrid object. You can call these methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with an object’s properties and methods from your scripts. However, when testing an XtraGrid control from your keyword test, you can use the same methods and properties calling them from keyword test operations. For more information, see Keyword Tests Basic Operations.

Using the Actions of DevExpressXtraGrid and DevExpressXtraGridView Objects

To expand or collapse rows in the XtraGrid control, you can use the Expand and Collapse actions of the DevExpressXtraGrid and DevExpressXtraGridView objects. The DevExpressXtraGrid object is applied to the rows of the main data view, whereas the DevExpressXtraGridView object affects the rows of the child data views. The wExpanded property lets you determine the current expanded state of a particular row. Similarly, to expand and collapse groups, use the ExpandGroup and CollapseGroup actions of the DevExpressXtraGrid or DevExpressXtraGridView objects, respectively. The wGroupExpanded property, in its turn, lets you check whether a particular group is expanded or collapsed.

The following example illustrates how you can expand and collapse rows and groups in the XtraGrid controls using the mentioned actions:

Show Example

Simulating Mouse and Keyboard Actions

It is possible to expand or collapse a row or group by double-clicking its indicator. You can simulate these clicks using the DblClickRowIndicator action of the DevExpressXtraGrid and DevExpressXtraGridView objects. The action affects both kinds of rows. The actual kind of a row is defined by the row index: data rows have positive or zero indexes, whereas group row indexes are negative.

Show Example

You can also expand and collapse XtraGrid rows and groups using the special keyboard shortcuts. For example, the Ctrl+Num Plus shortcut expands the currently selected row or group, and Ctrl+Num Minus collapses it. To send these keystrokes to the grid control, use the Keys action that is added to all onscreen objects by TestComplete.

The example below demonstrates how to expand and collapse XtraGrid rows by simulating keyboard shortcuts:

Show Example

Using Internal Methods of the XtraGrid Control

Another way to expand and collapse XtraGrid rows is to use the internal methods of the XtraGrid control. The following table lists methods that can be used to expand and collapse data rows and groups in the XtraGrid control. For more information on these methods, please refer to the XtraGrid Suite documentation.

Method Description
viewObj.ExpandMasterRow (RowIndex) Expands a data row specified by its index (zero-based).
viewObj.CollapseMasterRow (RowIndex) Collapses a data row specified by its index (zero-based).
viewObj.GetMasterRowExpanded (RowIndex) Return True if the specified data row is expanded; otherwise False.
viewObj.CollapseAllDetails() Collapses all data rows in the given view.
viewObj.ExpandGroupRow (GroupIndex) Expands a group specified by its internal index (-1-based).
viewObj.CollapseGroupRow (GroupIndex) Collapses a group specified by its internal index (-1-based).
viewObj.GetRowExpanded (GroupIndex) Returns True if the specified group is expanded, and False otherwise.
viewObj.ExpandAllGroups() Expands all groups in the given view.
viewObj.CollapseAllGroups() Collapses all groups in the given view.

As you can see, all of these methods apply to the view object that contains the desired row or group. To learn how you can obtain grid views, see Accessing Views in Developer Express XtraGrid. Also note that these methods take internal row indexes as parameters. Indexes of data rows are zero-based, meaning that they start with 0 and continue down the grid, for example, 0,1,2,3... Groups have negative indexes, starting with -1 and decreasing downwards. So, the first group’s index is -1, the index of the second one is -2, and so on.

Below is an example that demonstrates how you can use these methods to expand rows and groups in the XtraGrid control.

Show Example

As already mentioned, you can collapse all data rows in a particular grid view using the view’s CollapseAllDetails method. However, the XtraGrid control does not have built-in methods that let you expand all data rows at once. If you need this functionality in your tests, you can write a sample routine that calls the grid view’s ExpandMasterRow method for all rows in a loop. The following example demonstrates how you can do this:

Show Example

See also
Working With Developer Express XtraGrid - Overview | Accessing Views in Developer Express XtraGrid | Collapse Action (Grid Controls) | CollapseGroup Action (Grid Controls) | Expand Action (Grid Controls) | ExpandGroup Action (Grid Controls)

© 2014 SmartBear Software. All rights reserved.
Email Send feedback on this document