Accessing Views in Developer Express XtraGrid

Applies to TestComplete 15.47, last modified on January 20, 2023

The XtraGrid control can display data of multiple nested tables. The data of each child table as well as the parent table is displayed in a separate view. A view is an object that holds information about the data displayed in it, the number of rows and columns, appearance and behavior settings. Methods and properties of the DevExpressXtraGrid object that is used to work with XtraGrid controls from TestComplete scripts, as well as many custom examples in this section require that you specify the view under which the operation is applied. This topic explains how you can access the XtraGrid views.

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 plugins must be installed and enabled. The latter lets you work with the XtraGrid control using methods and properties of the DevExpressXtraGrid object. Without this plugin, 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.

Accessing Views Using the DevExpressXtraGrid.wChildView Property

Methods and properties of the DevExpressXtraGrid object let you work with data displayed in the top-level grid view. To access child views and work with child data, you can use the wChildView property. This property returns the DevExpressXtraGridView object that represents the specified child view. Similarly, you can access a grand-child view by using the wChildView property applied to a child view object, and so on. The wChildViewCount property lets you determine the number of child views for a particular grid row. You can use this property, for example, if you need to iterate through child views.

Note: The XtraGrid control architecture only allows child views to exist when they are displayed in the grid, that is, when their parent rows are expanded. When you access a child view using the wChildView property, TestComplete automatically expands the view’s parent row and selects this view, so that you do not have to perform any additional actions to expand the parent row.
Example

Below is an example that illustrates how you can work with several grid views.

The example works with the GridMainDemo application.

How to get the application

JavaScript, JScript

function Main ()
{
  var p, frmMain, Grid;

  // Obtain the application process and its main form
  p = Sys.Process("GridMainDemo");
  frmMain = p.WinFormsObject("frmMain");
  // Select the "Inplace Editors" demo
  frmMain.WinFormsObject("gcNavigations").WinFormsObject("navBarControl1").Groups.Item_2(1).SelectedLinkIndex = 0;
  // Obtain the grid control
  Grid = frmMain.WinFormsObject("panelControl1").WinFormsObject("gcContainer").WinFormsObject("MasterDetail").WinFormsObject("gridControl1");

  // Enter new data into the grid
  Grid.ClickCell(0, "Contact Name");
  Grid.Keys ("^a[Del]" + "John Smith" + "[Enter]");
  
  Grid.wChildView(0, "Products").ClickCell(0, "Product Name");
  Grid.Keys ("^a[Del]" + "Ipoh Coffee" + "[Enter]");

  Grid.wChildView(0, "Products").wChildView(0, "Order Details").ClickCell(0, "Quantity");
  Grid.Keys ("^a[Del]" + "75" + "[Enter]");
}

Python

def Main ():

  # Obtain the application process and its main form
  p = Sys.Process("GridMainDemo")
  frmMain = p.WinFormsObject("frmMain")
  frmMain.Activate
  # Select the "Master-Detail" demo
  frmMain.WinFormsObject("gcNavigations").WinFormsObject("navBarControl1").Groups.Item_2[1].SelectedLinkIndex = 0
  # Obtain the grid control
  Grid = frmMain.WinFormsObject("panelControl1").WinFormsObject("gcContainer").WinFormsObject("MasterDetail").WinFormsObject("gridControl1")

  # Enter new data into the grid
  Grid.ClickCell(0, "Contact Name")
  Grid.Keys ("^a[Del]" + "John Smith" + "[Enter]")
  
  Grid.wChildView[0, "Products"].ClickCell(0, "Product Name")
  Grid.Keys ("^a[Del]" + "Ipoh Coffee" + "[Enter]")

  Grid.wChildView[0, "Products"].wChildView[0, "Order Details"].ClickCell(0, "Quantity")
  Grid.Keys ("^a[Del]" + "75" + "[Enter]")

VBScript

Sub Main
  Dim p, frmMain, Grid

  ' Obtain the application process and its main form
  Set p = Sys.Process("GridMainDemo")
  Set frmMain = p.WinFormsObject("frmMain")
  frmMain.Activate
  ' Select the "Master-Detail" demo
  frmMain.WinFormsObject("gcNavigations").WinFormsObject("navBarControl1").Groups.Item_2(1).SelectedLinkIndex = 0
  ' Obtain the grid control
  Set Grid = frmMain.WinFormsObject("panelControl1").WinFormsObject("gcContainer").WinFormsObject("MasterDetail").WinFormsObject("gridControl1")

  ' Enter new data into the grid
  Call Grid.ClickCell(0, "Contact Name")
  Grid.Keys ("^a[Del]" & "John Smith" & "[Enter]")
  
  Call Grid.wChildView(0, "Products").ClickCell(0, "Product Name")
  Grid.Keys ("^a[Del]" & "Ipoh Coffee" & "[Enter]")

  Call Grid.wChildView(0, "Products").wChildView(0, "Order Details").ClickCell(0, "Quantity")
  Grid.Keys ("^a[Del]" & "75" & "[Enter]")
End Sub

DelphiScript

procedure Main;
var p, frmMain, Grid : OleVariant;
begin
  // Obtain the application process and its main form
  p := Sys.Process('GridMainDemo');
  frmMain := p.WinFormsObject('frmMain');
  frmMain.Activate;
  // Select the "Master-Detail" demo
  frmMain.WinFormsObject('gcNavigations').WinFormsObject('navBarControl1').Groups.Item_2[1].SelectedLinkIndex := 0;
  // Obtain the grid control
  Grid := frmMain.WinFormsObject('panelControl1').WinFormsObject('gcContainer').WinFormsObject('MasterDetail').WinFormsObject('gridControl1');

  // Enter new data into the grid
  Grid.ClickCell(0, 'Contact Name');
  Grid.Keys ('^a[Del]' + 'John Smith' + '[Enter]');
  
  Grid.wChildView[0, 'Products'].ClickCell(0, 'Product Name');
  Grid.Keys ('^a[Del]' + 'Ipoh Coffee' + '[Enter]');

  Grid.wChildView[0, 'Products'].wChildView[0, 'Order Details'].ClickCell(0, 'Quantity');
  Grid.Keys ('^a[Del]' + '75' + '[Enter]');
end;

C++Script, C#Script

function Main ()
{
  var p, frmMain, Grid;

  // Obtain the application process and its main form
  p = Sys["Process"]("GridMainDemo");
  frmMain = p["WinFormsObject"]("frmMain");
  // Select the "IMaster-Detail" demo
  frmMain["WinFormsObject"]("gcNavigations")["WinFormsObject"]("navBarControl1")["Groups"]["Item_2"](1)["SelectedLinkIndex"] = 0;
  // Obtain the grid control
  Grid = frmMain["WinFormsObject"]("panelControl1")["WinFormsObject"]("gcContainer")["WinFormsObject"]("MasterDetail")["WinFormsObject"]("gridControl1");

  // Enter new data into the grid
  Grid["ClickCell"](0, "Contact Name");
  Grid["Keys"]("^a[Del]" + "John Smith" + "[Enter]");

  Grid["wChildView"](0, "Products")["ClickCell"](0, "Product Name");
  Grid["Keys"]("^a[Del]" + "Ipoh Coffee" + "[Enter]");

  Grid["wChildView"](0, "Products")["wChildView"](0, "Order Details")["ClickCell"](0, "Quantity");
  Grid["Keys"]("^a[Del]" + "75" + "[Enter]");
}

Accessing Views Using XtraGrid’s Internal Properties and Methods

Sometimes you may need to get “native” .NET objects that represent a particular grid view. For example, you may want to perform specific actions or checks using internal methods and properties of the XtraGrid control.

The XtraGrid control provides special properties that let you quickly access specific views:

  • MainView provides access to the topmost grid view.
  • FocusedView provides access to the currently focused view. You can use this property, for example, to determine or set the focused view in a grid that displays data of multiple nested tables.
  • DefaultView returns the currently maximized grid view (it can be either MainView or a child view).

If the grid displays data of one table only, the FocusedView and DefaultView properties return the same view as the MainView property.

The following code snippet demonstrates how you can obtain the number of rows and columns in a currently focused grid view:

JavaScript, JScript

function Test ()
{
  var Grid, View;

  // Obtain the grid object
  ...
  // Obtain the currently focused grid view
  View = Grid.FocusedView;

  Log.Message ("The grid has " + View.RowCount + " rows and " + View.Columns.Count + " columns.");
}

Python

def Test ():

  # Obtain the grid object
  ...
  # Obtain the currently focused grid view
  View = Grid.FocusedView

  Log.Message ("The grid has " + View.RowCount + " rows and " + View.Columns.Count + " columns.")

VBScript

Sub Test
  Dim Grid, View

   ' Obtain the grid object
  ...
  ' Obtain the currently focused grid view
  Set View = Grid.FocusedView

  Call Log.Message ("The grid has " & View.RowCount & " rows and " & View.Columns.Count & " columns.")
End Sub

DelphiScript

procedure Test;
var Grid, View : OleVariant;
begin
  // Obtain the grid object
  ...
  // Obtain the currently focused grid view
  View := Grid.FocusedView;

  Log.Message ('The grid has ' + aqConvert.VarToStr(View.RowCount) + ' rows and ' + aqConvert.VarToStr(View.Columns.Count) + ' columns.');
end;

C++Script, C#Script

function Test ()
{
  var Grid, View;

  // Obtain the grid object
  ...
  // Obtain the currently focused grid view
  View = Grid["FocusedView"];

  Log["Message"]("The grid has " + View["RowCount"] + " rows and " + View["Columns"]["Count"] + " columns.");
}

If the grid displays hierarchical data, you will need to work with the data displayed in the top-level view as well as in its child views. To obtain a “native” child view object, you need to create a script that performs the following actions:

  • Expands the view’s parent row. This is needed, because child views in the XtraGrid control only exist when they are displayed in the grid. To learn how you can expand XtraGrid rows, see Expanding and Collapsing Rows in Developer Express XtraGrid.
  • Selects the desired child view, among child views of its parent row. Due to the above-mentioned specific, if the row has several child views, you need to switch to the desired child view in order to be able to access it. You can select a child view by its index (zero-based) using the following SetMasterRowExpandedEx method of the parent view object:
    viewObj.SetMasterRowExpandedEx(RowIndex, ChildViewIndex, true)
  • Obtains the desired child view. For this purpose, use the GetVisibleDetailView method of the parent view object. It returns the currently displayed child view for the specified row:
    viewObj.GetVisibleDetailView(RowIndex)
Example

Below is an example that demonstrates how you can access and work with views in the XtraGrid control using its internal properties and methods.

The example works with the GridMainDemo application.

How to get the application

View example description

JavaScript

function Main ()
{
  var p, frmMain, Grid, ChildView;

  // Obtain the application process and its main form
  p = Sys.Process("GridMainDemo");
  frmMain = p.WinFormsObject("frmMain");
  frmMain.Maximize();
  // Select the "Master-Detail" demo
  frmMain.WinFormsObject("gcNavigations").WinFormsObject("navBarControl1").Groups.Item_2(1).SelectedLinkIndex = 0;
  // Obtain the grid control
  Grid = frmMain.WinFormsObject("panelControl1").WinFormsObject("gcContainer").WinFormsObject("MasterDetail").WinFormsObject("gridControl1");

  // Simulate actions in the top-level view
  SelectCell (Grid, null, 0, "Contact Name");
  Grid.Keys ("[F2]" + "John Smith" + "[Enter]");

  // Simulate actions in the "Products" child view
  ChildView = GetChildView (Grid, null, 0, 1);
  SelectCell (Grid, ChildView, 0, "Product Name");
  Grid.Keys ("[F2]" + "Ipoh Coffee" + "[Enter]");

  // Simulate actions in the "Order Details" child view
  ChildView = GetChildView (Grid, ChildView, 0, 0);
  SelectCell (Grid, ChildView, 0, "Quantity");
  Grid.Keys ("[F2]" + "75" + "[Enter]");
}

function GetChildView (Grid, ParentView, RowIndex, ChildViewIndex)
{
  if (strictEqual(ParentView, null))
    ParentView = Grid.MainView;

  // Make the child view visible
  ParentView.SetMasterRowExpandedEx (RowIndex, ChildViewIndex, true);
  // Obtain the view object and return it
  return ParentView.GetVisibleDetailView(RowIndex);
}

function SelectCell (Grid, View, RowIndex, ColumnId)
{
  // Get the grid view object, if it is not specified
  if (isNull(View))
    View = Grid.MainView;

  // Set the focused view
  Grid.FocusedView = View;
  // Change the row and column focus
  View.FocusedRowHandle = RowIndex;
  View.FocusedColumn = GetColumn (Grid, View, ColumnId);
}

function GetColumn (Grid, View, ColumnId)
{
  var Columns, Col;

  // Get the grid view object, if it is not specified
  if (isNull(View))
    View = Grid.MainView;

  Columns = View.Columns;
  // Check if the column is specified by caption or index
  if (equal(aqObject.GetVarType (ColumnId), varOleStr))
  {
    // Search for the column by its caption
    for (let i=0; i<Columns.Count; i++)
    {
      Col = Columns.Item_2(i);
      if (equal(Col.Caption.OleValue, ColumnId))
        return Col; // The column is found
    }
    return null; // The column is not found
  }
  else
    // The column is specified by index
    return Columns.Item_2(ColumnId);
}

JScript

function Main ()
{
  var p, frmMain, Grid, ChildView;

  // Obtain the application process and its main form
  p = Sys.Process("GridMainDemo");
  frmMain = p.WinFormsObject("frmMain");
  frmMain.Maximize();
  // Select the "Master-Detail" demo
  frmMain.WinFormsObject("gcNavigations").WinFormsObject("navBarControl1").Groups.Item_2(1).SelectedLinkIndex = 0;
  // Obtain the grid control
  Grid = frmMain.WinFormsObject("panelControl1").WinFormsObject("gcContainer").WinFormsObject("MasterDetail").WinFormsObject("gridControl1");

  // Simulate actions in the top-level view
  SelectCell (Grid, null, 0, "Contact Name");
  Grid.Keys ("[F2]" + "John Smith" + "[Enter]");

  // Simulate actions in the "Products" child view
  ChildView = GetChildView (Grid, null, 0, 1);
  SelectCell (Grid, ChildView, 0, "Product Name");
  Grid.Keys ("[F2]" + "Ipoh Coffee" + "[Enter]");

  // Simulate actions in the "Order Details" child view
  ChildView = GetChildView (Grid, ChildView, 0, 0);
  SelectCell (Grid, ChildView, 0, "Quantity");
  Grid.Keys ("[F2]" + "75" + "[Enter]");
}

function GetChildView (Grid, ParentView, RowIndex, ChildViewIndex)
{
  if (ParentView == null)
    ParentView = Grid.MainView;

  // Make the child view visible
  ParentView.SetMasterRowExpandedEx (RowIndex, ChildViewIndex, true);
  // Obtain the view object and return it
  return ParentView.GetVisibleDetailView(RowIndex);
}

function SelectCell (Grid, View, RowIndex, ColumnId)
{
  // Get the grid view object, if it is not specified
  if (View == null)
    View = Grid.MainView;

  // Set the focused view
  Grid.FocusedView = View;
  // Change the row and column focus
  View.FocusedRowHandle = RowIndex;
  View.FocusedColumn = GetColumn (Grid, View, ColumnId);
}

function GetColumn (Grid, View, ColumnId)
{
  var Columns, Col, i;

  // Get the grid view object, if it is not specified
  if (View == null)
    View = Grid.MainView;

  Columns = View.Columns;
  // Check if the column is specified by caption or index
  if (aqObject.GetVarType (ColumnId) == varOleStr)
  {
    // Search for the column by its caption
    for (i=0; i<Columns.Count; i++)
    {
      Col = Columns.Item_2(i);
      if (Col.Caption.OleValue == ColumnId)
        return Col; // The column is found
    }
    return null; // The column is not found
  }
  else
    // The column is specified by index
    return Columns.Item_2(ColumnId);
}

Python

def Main ():

  # Obtain the application process and its main form
  p = Sys.Process("GridMainDemo")
  frmMain = p.WinFormsObject("frmMain")
  frmMain.Maximize()
  # Select the "Master-Detail" demo
  frmMain.WinFormsObject("gcNavigations").WinFormsObject("navBarControl1").Groups.Item_2[1].SelectedLinkIndex = 0
  # Obtain the grid control
  Grid = frmMain.WinFormsObject("panelControl1").WinFormsObject("gcContainer").WinFormsObject("MasterDetail").WinFormsObject("gridControl1")

  # Simulate actions in the top-level view
  SelectCell (Grid, None, 0, "Contact Name")
  Grid.Keys ("[F2]" + "John Smith" + "[Enter]")

  # Simulate actions in the "Products" child view
  ChildView = GetChildView (Grid, None, 0, 1)
  SelectCell (Grid, ChildView, 0, "Product Name")
  Grid.Keys ("[F2]" + "Ipoh Coffee" + "[Enter]")

  # Simulate actions in the "Order Details" child view
  ChildView = GetChildView (Grid, ChildView, 0, 0)
  SelectCell (Grid, ChildView, 0, "Quantity")
  Grid.Keys ("[F2]" + "75" + "[Enter]")

def GetChildView (Grid, ParentView, RowIndex, ChildViewIndex):
  if ParentView == None:
    ParentView = Grid.MainView

  # Make the child view visible
  ParentView.SetMasterRowExpandedEx (RowIndex, ChildViewIndex, True)
  # Obtain the view object and return it
  return ParentView.GetVisibleDetailView(RowIndex)

def SelectCell (Grid, View, RowIndex, ColumnId):
  # Get the grid view object, if it is not specified
  if (View == None):
    View = Grid.MainView

  # Set the focused view
  Grid.FocusedView = View
  # Change the row and column focus
  View.FocusedRowHandle = RowIndex
  View.FocusedColumn = GetColumn (Grid, View, ColumnId)

def GetColumn (Grid, View, ColumnId):

  # Get the grid view object, if it is not specified
  if (View == None):
    View = Grid.MainView

  Columns = View.Columns
  # Check if the column is specified by caption or index
  if (aqObject.GetVarType (ColumnId) == varOleStr):
    # Search for the column by its caption
    for i in range(0, Columns.Count-1):
      Col = Columns.Item_2[i]
      if (Col.Caption.OleValue == ColumnId):
        return Col # The column is found
    return None # The column is not found
  else:
    # The column is specified by index
    return Columns.Item_2[ColumnId]

VBScript

Sub Main
  Dim p, frmMain, Grid, ChildView

  ' Obtain the application process and its main form
  Set p = Sys.Process("GridMainDemo")
  Set frmMain = p.WinFormsObject("frmMain")
  frmMain.Maximize
  ' Select the "Master-Detail" demo
  frmMain.WinFormsObject("gcNavigations").WinFormsObject("navBarControl1").Groups.Item_2(1).SelectedLinkIndex = 0
  ' Obtain the grid control
  Set Grid = frmMain.WinFormsObject("panelControl1").WinFormsObject("gcContainer").WinFormsObject("MasterDetail").WinFormsObject("gridControl1")

  ' Simulate actions in the top-level view
  Call SelectCell (Grid, Nothing, 0, "Contact Name")
  Grid.Keys ("[F2]" & "John Smith" & "[Enter]")

  ' Simulate actions in the "Products" child view
  Set ChildView = GetChildView (Grid, Nothing, 0, 1)
  Call SelectCell (Grid, ChildView, 0, "Product Name")
  Grid.Keys ("[F2]" & "Ipoh Coffee" & "[Enter]")

  ' Simulate actions in the "Order Details" child view
  Set ChildView = GetChildView (Grid, ChildView, 0, 0)
  Call SelectCell (Grid, ChildView, 0, "Quantity")
  Grid.Keys ("[F2]" & "75" & "[Enter]")
End Sub

Function GetChildView (Grid, ParentView, RowIndex, ChildViewIndex)
  If ParentView Is Nothing Then
    Set ParentView = Grid.MainView
  End If

  ' Make the child view visible
  Call ParentView.SetMasterRowExpandedEx (RowIndex, ChildViewIndex, True)
  ' Obtain the view object and return it
  Set GetChildView = ParentView.GetVisibleDetailView(RowIndex)
End Function

Sub SelectCell (Grid, View, RowIndex, ColumnId)
  ' Get the grid view object, if it is not specified
  If View Is Nothing Then
    Set View = Grid.MainView
  End If

  ' Set the focused view
  Set Grid.FocusedView = View
  ' Change the row and column focus
  View.FocusedRowHandle = RowIndex
  Set View.FocusedColumn = GetColumn (Grid, View, ColumnId)
End Sub

Function GetColumn (Grid, View, ColumnId)
  Dim Columns, Col, i

  ' Get the grid view object, if it is not specified
  If View Is Nothing Then
    Set View = Grid.MainView
  End If

  Set Columns = View.Columns
  ' Check if the column is specified by caption or index
  If aqObject.GetVarType(ColumnId) = varOleStr Then
    ' Search for the column by its caption
    For i = 0 To Columns.Count-1
      Set Col = Columns.Item_2(i)
      If Col.Caption.OleValue = ColumnId Then
        Set GetColumn = Col ' The column is found
        Exit Function
      End If
    Next

    Set GetColumn = Nothing' The column is not found
  Else
    ' The column is specified by index
    Set GetColumn = Columns.Item_2(ColumnId)
  End If
End Function

DelphiScript

function GetChildView (Grid, ParentView, RowIndex, ChildViewIndex); forward;
procedure SelectCell (Grid, View, RowIndex, ColumnId); forward;
function GetColumn (Grid, View, ColumnId); forward;

procedure Main;
var p, frmMain, Grid, ChildView: OleVariant;
begin
  // Obtain the application process and its main form
  p := Sys.Process('GridMainDemo');
  frmMain := p.WinFormsObject('frmMain');
  frmMain.Maximize;
  // Select the ;Master-Detail; demo
  frmMain.WinFormsObject('gcNavigations').WinFormsObject('navBarControl1').Groups.Item_2[1].SelectedLinkIndex := 0;
  // Obtain the grid control
  Grid := frmMain.WinFormsObject('panelControl1').WinFormsObject('gcContainer').WinFormsObject('MasterDetail').WinFormsObject('gridControl1');

  // Simulate actions in the top-level view
  SelectCell (Grid, nil, 0, 'Contact Name');
  Grid.Keys ('[F2]' + 'John Smith' + '[Enter]');

  // Simulate actions in the 'Products' child view
  ChildView := GetChildView (Grid, nil, 0, 1);
  SelectCell (Grid, ChildView, 0, 'Product Name');
  Grid.Keys ('[F2]' + 'Ipoh Coffee' + '[Enter]');

  // Simulate actions in the 'Order Details' child view
  ChildView := GetChildView (Grid, ChildView, 0, 0);
  SelectCell (Grid, ChildView, 0, 'Quantity');
  Grid.Keys ('[F2]' + '75' + '[Enter]');
end;

function GetChildView (Grid, ParentView, RowIndex, ChildViewIndex);
begin
  if ParentView = nil then
    ParentView := Grid.MainView;

  // Make the child view visible
  ParentView.SetMasterRowExpandedEx (RowIndex, ChildViewIndex, true);
  // Obtain the view object and return it
  Result := ParentView.GetVisibleDetailView(RowIndex);
end;

procedure SelectCell (Grid, View, RowIndex, ColumnId);
begin
  // Get the grid view object, if it is not specified
  if View = nil then
    View := Grid.MainView;

  // Set the focused view
  Grid.FocusedView := View;
  // Change the row and column focus
  View.FocusedRowHandle := RowIndex;
  View.FocusedColumn := GetColumn (Grid, View, ColumnId);
end;

function GetColumn (Grid, View, ColumnId);
var Columns, Col, i : OleVariant;
begin
  // Get the grid view object, if it is not specified
  if View = nil then
    View := Grid.MainView;

  Columns := View.Columns;
  // Check if the column is specified by caption or index
  if aqObject.GetVarType (ColumnId) = varOleStr then
  begin
    // Search for the column by its caption
    for i := 0 to Columns.Count-1 do
    begin
      Col := Columns.Item_2[i];
      if Col.Caption.OleValue = ColumnId then
      begin
        Result := Col; // The column is found
        Exit
      end
    end;

    Result := nil; // The column is not found
  end
  else
    // The column is specified by index
    Result := Columns.Item_2[ColumnId];
end;

C++Script, C#Script

function Main ()
{
  var p, frmMain, Grid, ChildView;

  // Obtain the application process and its main form
  p = Sys["Process"]("GridMainDemo");
  frmMain = p["WinFormsObject"]("frmMain");
  frmMain["Maximize"]();
  // Select the "Master-Detail" demo
  frmMain["WinFormsObject"]("gcNavigations")["WinFormsObject"]("navBarControl1")["Groups"]["Item_2"](1)["SelectedLinkIndex"] = 0;
  // Obtain the grid control
  Grid = frmMain["WinFormsObject"]("panelControl1")["WinFormsObject"]("gcContainer")["WinFormsObject"]("MasterDetail")["WinFormsObject"]("gridControl1");

  // Simulate actions in the top-level view
  SelectCell (Grid, null, 0, "Contact Name");
  Grid["Keys"]("[F2]" + "John Smith" + "[Enter]");

  // Simulate actions in the "Products" child view
  ChildView = GetChildView (Grid, null, 0, 1);
  SelectCell (Grid, ChildView, 0, "Product Name");
  Grid["Keys"]("[F2]" + "Ipoh Coffee" + "[Enter]");

  // Simulate actions in the "Order Details" child view
  ChildView = GetChildView (Grid, ChildView, 0, 0);
  SelectCell (Grid, ChildView, 0, "Quantity");
  Grid["Keys"]("[F2]" + "75" + "[Enter]");
}

function GetChildView (Grid, ParentView, RowIndex, ChildViewIndex)
{
  if (ParentView == null)
    ParentView = Grid["MainView"];

  // Make the child view visible
  ParentView["SetMasterRowExpandedEx"](RowIndex, ChildViewIndex, true);
  // Obtain the view object and return it
  return ParentView["GetVisibleDetailView"](RowIndex);
}

function SelectCell (Grid, View, RowIndex, ColumnId)
{
  // Get the grid view object, if it is not specified
  if (View == null)
    View = Grid["MainView"];

  // Set the focused view
  Grid["FocusedView"] = View;
  // Change the row and column focus
  View["FocusedRowHandle"] = RowIndex;
  View["FocusedColumn"] = GetColumn (Grid, View, ColumnId);
}

function GetColumn (Grid, View, ColumnId)
{
  var Columns, Col, i;

  // Get the grid view object, if it is not specified
  if (View == null)
    View = Grid["MainView"];

  Columns = View["Columns"];
  // Check if the column is specified by caption or index
  if (aqObject["GetVarType"](ColumnId) == varOleStr)
  {
    // Search for the column by its caption
    for (i=0; i<Columns["Count"]; i++)
    {
      Col = Columns["Item_2"](i);
      if (Col["Caption"]["OleValue"] == ColumnId)
        return Col; // The column is found
    }
    return null; // The column is not found
  }
  else
    // The column is specified by index
    return Columns["Item_2"](ColumnId);
}

See Also

Working With Developer Express XtraGrid
wChildView Property (Grid Controls)
wChildViewCount Property (Grid Controls)
Expanding and Collapsing Rows in Developer Express XtraGrid

Highlight search results