Iterating Through Rows and Cards in Developer Express XtraGrid

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

Iterating through grid rows means accessing rows is a series, one by one. You may need to iterate through XtraGrid rows if you need to locate a particular row in the grid, or perform the same set of operations on each row.

The following sections explain how to iterate through rows in the XtraGrid control. The Example section contains a script example that exports the grid data to an XML file. Note that this topic only provides general information about processing rows (cards) in the XtraGrid control. For advanced information, please refer to the XtraGrid Suite documentation.

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.

Iterating Through Data Rows and Cards

To determine the total number of data rows (cards) in the XtraGrid control or its child view, use the wRowCount property of the DevExpressXtraGrid object that corresponds to the grid or the DevExpressXtraGridView object that corresponds to the child view. Alternatively, you can use the DataRowCount property of a “native” object that corresponds to the view (to lean how you can obtain this object, see Accessing Views in Developer Express XtraGrid). To iterate through the rows (cards), you need to organize a loop whose counter changes from 0 (index of the first data row/card) to the number of rows/cards-1 (which is index of the last row/card). On each loop iteration, you can perform the needed actions with the current row (card). For example, you can modify values in its cells or save them to a file.

Iterating Through Groups

The XtraGrid control supports hierarchical data representation. The grid data can be grouped by one or several columns so that data rows are organized into one-level or multi-level nested groups. You can loop through groups in the same way as through data rows (cards). On each loop step, you can perform the desired action with the current group, for example, expand or collapse it.

To determine the number of groups in a grid or its child view, use the DevExpressXtraGrid.wGroupCount property of the DevExpressXtraGrid object that corresponds to the grid or the DevExpressXtraGridView object that corresponds to the child view. You can also get the number of groups in a grid view via the DataController.GroupRowCount property of a “native” object that corresponds to this view.

Note: When working with groups using internal methods and properties of the XtraGrid control, remember that group indexes are negative. They start from -1 and decrease down the grid, so, the loop counter should change from -1 to -viewObj.DataController.GroupRowCount, inclusively.

Processing Child Views

If the XtraGrid control displays data of multiple nested tables, then each row in a parent table can have child data. So, besides processing the row data itself, you may need to iterate through its child data as well.

You can determine the number of child views for a particular grid row using the wChildViewCount property. To get a child view by its index or caption, use the wChildView property. After you have obtained a child view, you can also iterate through its rows and process them.

If you are working with the XtraGrid control using its internal methods and properties, you can determine the child view count for a grid row using the view’s GetRelationCount (RowIndex) property. The view’s GetDetailView (RowIndexChildViewIndex) method lets you obtain a child view by its index. For more information on how to access child views, see Accessing Views in Developer Express XtraGrid and the XtraGrid Suite documentation.

Note: When working with child views using internal methods and properties of the XtraGrid control, remember that child views are created at run-time, when their parent rows are expanded. That is, to access a detail view for a particular master row, you need to expand it first (see Expanding and Collapsing Rows in Developer Express XtraGrid).

Example

The example below demonstrates how you can iterate through grid records and save the grid data, including column (card field) captions, to an XML file. The script works equally well for both grid and card views. It processes the data of the top-level view as well as child views. Note that the script only exports the actual grid data and does not save the grid’s grouping state.

The example works with the GridMainDemo application.

How to get the application

View example description

JavaScript

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

  // Obtain the application process and its main form
  p = Sys.Process("GridMainDemo");
  frmMain = p.WinFormsObject("frmMain");

  // 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");

  // Export the grid contents to an XML file
  FileName = "C:\\GridData.xml";
  ExportToXml (Grid, FileName);
  Log.File (FileName, "Exported grid data.");
}

function ExportToXml (GridOrView, FileName)
{
  Indicator.PushText ("Exporting the grid data to a file...");

  // Create a text file and open it for writing
  let Overwrite = true;
  let Unicode = true;
  let fso = getActiveXObject("Scripting.FileSystemObject");
  let XmlFile = fso.CreateTextFile (FileName, Overwrite, Unicode);

  // Write the root tag
  XmlFile.WriteLine ("<grid>");
  ExportView (GridOrView, XmlFile, "  ");
  // Close the root tag
  XmlFile.WriteLine ("</grid>");

  // Close the file
  XmlFile.Close();

  Indicator.PopText();
}

function ExportView (ViewObj, XmlFile, indent)
{
  var ViewCaption, ColCaption, CellText;

  // Write the opening tag
  ViewCaption = ReplaceSpecialChars (ViewObj.wViewName);
  XmlFile.WriteLine (indent + "<view caption=\"" + ViewCaption + "\">");

  // Write column captions
  XmlFile.WriteLine (indent + "  <columns>");
  for (let i = 0; i < ViewObj.wColumnCount; i++)
  {
    ColCaption = ReplaceSpecialChars (ViewObj.wColumn(i));
    XmlFile.WriteLine (indent + "    <column>" + ColCaption + "</column>");
  }
  XmlFile.WriteLine (indent + "  </columns>");

  // Iterate through data rows/cards and export their data
  XmlFile.WriteLine (indent + "  <rows>");
  for (let i = 0; i < ViewObj.wRowCount; i++)
  {
    XmlFile.WriteLine (indent + "    <row>");
    for (let j = 0; j < ViewObj.wColumnCount; j++)
    {
      // Get the text representation of the cell value
      CellText = ViewObj.wValue(i, j).ToString().OleValue;
      CellText = ReplaceSpecialChars (CellText); // Replace special characters
      XmlFile.WriteLine (indent + "      <cell>" + CellText + "</cell>");
    }

    // Check if the row has child data
    if (ViewObj.wChildViewCount(i) > 0)
    {
      // Export child views
      XmlFile.WriteLine (indent + "      <childviews>");
      for (let j = 0; j < ViewObj.wChildViewCount(i); j++)
        ExportView (ViewObj.wChildView(i, j), XmlFile, indent + "        ");
      XmlFile.WriteLine (indent + "      </childviews>");
    }

    XmlFile.WriteLine (indent + "    </row>");
  }
  XmlFile.WriteLine (indent + "  </rows>");

  // Write the closing tag
  XmlFile.WriteLine (indent + "</view>");
}

function ReplaceSpecialChars (str)
{
  let s;
  s = aqString.Replace (str, "&", "&amp;", true);
  s = aqString.Replace (s, "<", "&lt;", true);
  s = aqString.Replace (s, ">", "&gt;", true);
  s = aqString.Replace (s, "\"", "&quot;", true);
  s = aqString.Replace (s, "'", "&apos;", true);
  return s;
}

JScript

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

  // Obtain the application process and its main form
  p = Sys.Process("GridMainDemo");
  frmMain = p.WinFormsObject("frmMain");

  // 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");

  // Export the grid contents to an XML file
  FileName = "C:\\GridData.xml";
  ExportToXml (Grid, FileName);
  Log.File (FileName, "Exported grid data.");
}

function ExportToXml (GridOrView, FileName)
{
  Indicator.PushText ("Exporting the grid data to a file...");

  // Create a text file and open it for writing
  var Overwrite = true;
  var Unicode = true;
  var fso = new ActiveXObject ("Scripting.FileSystemObject");
  var XmlFile = fso.CreateTextFile (FileName, Overwrite, Unicode);

  // Write the root tag
  XmlFile.WriteLine ("<grid>");
  ExportView (GridOrView, XmlFile, "  ");
  // Close the root tag
  XmlFile.WriteLine ("</grid>");

  // Close the file
  XmlFile.Close();

  Indicator.PopText();
}

function ExportView (ViewObj, XmlFile, indent)
{
  var ViewCaption, ColCaption, i, j, CellText;

  // Write the opening tag
  ViewCaption = ReplaceSpecialChars (ViewObj.wViewName);
  XmlFile.WriteLine (indent + "<view caption=\"" + ViewCaption + "\">");

  // Write column captions
  XmlFile.WriteLine (indent + "  <columns>");
  for (i = 0; i < ViewObj.wColumnCount; i++)
  {
    ColCaption = ReplaceSpecialChars (ViewObj.wColumn(i));
    XmlFile.WriteLine (indent + "    <column>" + ColCaption + "</column>");
  }
  XmlFile.WriteLine (indent + "  </columns>");

  // Iterate through data rows/cards and export their data
  XmlFile.WriteLine (indent + "  <rows>");
  for (i = 0; i < ViewObj.wRowCount; i++)
  {
    XmlFile.WriteLine (indent + "    <row>");
    for (j = 0; j < ViewObj.wColumnCount; j++)
    {
      // Get the text representation of the cell value
      CellText = ViewObj.wValue(i, j).ToString().OleValue;
      CellText = ReplaceSpecialChars (CellText); // Replace special characters
      XmlFile.WriteLine (indent + "      <cell>" + CellText + "</cell>");
    }

    // Check if the row has child data
    if (ViewObj.wChildViewCount(i) > 0)
    {
      // Export child views
      XmlFile.WriteLine (indent + "      <childviews>");
      for (j = 0; j < ViewObj.wChildViewCount(i); j++)
        ExportView (ViewObj.wChildView(i, j), XmlFile, indent + "        ");
      XmlFile.WriteLine (indent + "      </childviews>");
    }

    XmlFile.WriteLine (indent + "    </row>");
  }
  XmlFile.WriteLine (indent + "  </rows>");

  // Write the closing tag
  XmlFile.WriteLine (indent + "</view>");
}

function ReplaceSpecialChars (str)
{
  var s;
  s = aqString.Replace (str, "&", "&amp;", true);
  s = aqString.Replace (s, "<", "&lt;", true);
  s = aqString.Replace (s, ">", "&gt;", true);
  s = aqString.Replace (s, "\"", "&quot;", true);
  s = aqString.Replace (s, "'", "&apos;", true);
  return s;
}

Python

def Main ():

  # Obtain the application process and its main form
  p = Sys.Process("GridMainDemo")
  frmMain = p.WinFormsObject("frmMain")

  # 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")

  # Export the grid contents to an XML file
  FileName = "C:\\GridData.xml"
  ExportToXml (Grid, FileName)
  Log.File (FileName, "Exported grid data.")

def ExportToXml (GridOrView, FileName):
  Indicator.PushText ("Exporting the grid data to a file...")

  # Create a text file and open it for writing
  Overwrite = True
  Unicode = True
  fso = Sys.OleObject ['Scripting.FileSystemObject']
  XmlFile = fso.CreateTextFile (FileName, Overwrite, Unicode)

  # Write the root tag
  XmlFile.WriteLine ("<grid>")
  ExportView (GridOrView, XmlFile, "  ")
  # Close the root tag
  XmlFile.WriteLine ("</grid>")

  # Close the file
  XmlFile.Close()

  Indicator.PopText()

def ExportView (ViewObj, XmlFile, indent):

  # Write the opening tag
  ViewCaption = ReplaceSpecialChars (ViewObj.wViewName)
  XmlFile.WriteLine (indent + "<view caption=\"" + ViewCaption + "\">")

  # Write column captions
  XmlFile.WriteLine (indent + "  <columns>")
  for i in range(0, ViewObj.wColumnCount-1):
    ColCaption = ReplaceSpecialChars (ViewObj.wColumn(i))
    XmlFile.WriteLine (indent + "    <column>" + ColCaption + "</column>")
  XmlFile.WriteLine (indent + "  </columns>")

  # Iterate through data rows/cards and export their data
  XmlFile.WriteLine (indent + "  <rows>")
  for i in range(0, ViewObj.wRowCount-1):
    XmlFile.WriteLine (indent + "    <row>")
    for j in range(0, ViewObj.wColumnCount-1):
      # Get the text representation of the cell value
      CellText = ViewObj.wValue[i, j].ToString().OleValue
      CellText = ReplaceSpecialChars (CellText) # Replace special characters
      XmlFile.WriteLine (indent + "      <cell>" + CellText + "</cell>")

    # Check if the row has child data
    if (ViewObj.wChildViewCount(i) > 0):
      # Export child views
      XmlFile.WriteLine (indent + "      <childviews>")
      for j in range(0, ViewObj.wChildViewCount(i)):
        ExportView (ViewObj.wChildView[i, j], XmlFile, indent + "        ")
      XmlFile.WriteLine (indent + "      </childviews>")

    XmlFile.WriteLine (indent + "    </row>")
  XmlFile.WriteLine (indent + "  </rows>")

  # Write the closing tag
  XmlFile.WriteLine (indent + "</view>")

def ReplaceSpecialChars (str):
  s = aqString.Replace (str, "&", "&amp;", True)
  s = aqString.Replace (s, "<", "&lt;", True)
  s = aqString.Replace (s, ">", "&gt;", True)
  s = aqString.Replace (s, "\"", "&quot;", True)
  s = aqString.Replace (s, "'", "&apos;", True)
  return s

VBScript

Sub Main
  Dim p, frmMain, Grid, FileName

  ' Obtain the application process and its main form
  Set p = Sys.Process("GridMainDemo")
  Set frmMain = p.WinFormsObject("frmMain")

  ' 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")

  ' Export the grid contents to an XML file
  FileName = "C:\GridData.xml"
  Call ExportToXml (Grid, FileName)
  Call Log.File (FileName, "Exported grid data.")
End Sub

Sub ExportToXml (GridOrView, FileName)
  Dim fso, XmlFile, Overwrite, Unicode
  
  Indicator.PushText ("Exporting the grid data to a file...")

  ' Create a text file and open it for writing
  Overwrite = True
  Unicode = True
  Set fso = CreateObject ("Scripting.FileSystemObject")
  Set XmlFile = fso.CreateTextFile (FileName, Overwrite, Unicode)

  ' Write the root tag
  XmlFile.WriteLine ("<grid>")
  Call ExportView (GridOrView, XmlFile, "  ")
  ' Close the root tag
  XmlFile.WriteLine ("</grid>")

  ' Close the file
  XmlFile.Close

  Indicator.PopText
End Sub

Sub ExportView (ViewObj, XmlFile, indent)
  Dim ViewCaption, ColCaption, i, j, CellText

  ' Write the opening tag
  ViewCaption = ReplaceSpecialChars (ViewObj.wViewName)
  XmlFile.WriteLine (indent & "<view caption=""" & ViewCaption + """>")

  ' Write column captions
  XmlFile.WriteLine (indent & "  <columns>")
  For i = 0 To ViewObj.wColumnCount-1
    ColCaption = ReplaceSpecialChars (ViewObj.wColumn(i))
    XmlFile.WriteLine (indent & "    <column>" & ColCaption & "</column>")
  Next
  XmlFile.WriteLine (indent & "  </columns>")

  ' Iterate through data rows/cards and export their data
  XmlFile.WriteLine (indent & "  <rows>")
  For i = 0 To ViewObj.wRowCount-1
    XmlFile.WriteLine (indent & "    <row>")
    For j = 0 To ViewObj.wColumnCount-1
      ' Get the text representation of the cell value
      CellText = ViewObj.wValue(i, j).ToString.OleValue
      CellText = ReplaceSpecialChars (CellText) ' Replace special characters
      XmlFile.WriteLine (indent & "      <cell>" & CellText & "</cell>")
    Next

    ' Check if the row has child data
    If ViewObj.wChildViewCount(i) > 0 Then
      ' Export child views
      XmlFile.WriteLine (indent & "      <childviews>")
      For j = 0 To ViewObj.wChildViewCount(i)-1
        Call ExportView (ViewObj.wChildView(i, j), XmlFile, indent + "        ")
      Next
      XmlFile.WriteLine (indent & "      </childviews>")
    End If

    XmlFile.WriteLine (indent & "    </row>")
  Next
  XmlFile.WriteLine (indent & "  </rows>")

  ' Write the closing tag
  XmlFile.WriteLine (indent & "</view>")
End Sub

Function ReplaceSpecialChars (str)
  Dim s
  s = aqString.Replace (str, "&", "&amp;", True)
  s = aqString.Replace (s, "<", "&lt;", True)
  s = aqString.Replace (s, ">", "&gt;", True)
  s = aqString.Replace (s, """", "&quot;", True)
  s = aqString.Replace (s, "'", "&apos;", True)
  ReplaceSpecialChars = s
End Function

DelphiScript

procedure ExportToXml (GridOrView, FileName); forward;
procedure ExportView (ViewObj, XmlFile, indent); forward;
function ReplaceSpecialChars (str); forward;

procedure Main;
var p, frmMain, Grid, FileName : OleVariant;
begin
  // Obtain the application process and its main form
  p := Sys.Process('GridMainDemo');
  frmMain := p.WinFormsObject('frmMain');

  // 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');

  // Export the grid contents to an XML file
  FileName := 'C:\GridData.xml';
  ExportToXml (Grid, FileName);
  Log.File (FileName, 'Exported grid data.');
end;

procedure ExportToXml (GridOrView, FileName);
var fso, XmlFile, Overwrite, Unicode : OleVariant;
begin
  Indicator.PushText ('Exporting the grid data to a file...');

  // Create a text file and open it for writing
  Overwrite := true;
  Unicode := true;
  fso := Sys.OleObject ('Scripting.FileSystemObject');
  XmlFile := fso.CreateTextFile (FileName, Overwrite, Unicode);

  // Write the root tag
  XmlFile.WriteLine ('<grid>');
  ExportView (GridOrView, XmlFile, '  ');
  // Close the root tag
  XmlFile.WriteLine ('</grid>');

  // Close the file
  XmlFile.Close;

  Indicator.PopText;
end;

procedure ExportView (ViewObj, XmlFile, indent);
var ViewCaption, ColCaption, i, j, CellText : OleVariant;
begin
  // Write the opening tag
  ViewCaption := ReplaceSpecialChars (ViewObj.wViewName);
  XmlFile.WriteLine (indent + '<view caption:="' + ViewCaption + '">');

  // Write column captions
  XmlFile.WriteLine (indent + '  <columns>');
  for i := 0 to ViewObj.wColumnCount-1 do
  begin
    ColCaption := ReplaceSpecialChars (ViewObj.wColumn[i]);
    XmlFile.WriteLine (indent + '    <column>' + ColCaption + '</column>');
  end;
  XmlFile.WriteLine (indent + '  </columns>');

  // Iterate through data rows/cards and export their data
  XmlFile.WriteLine (indent + '  <rows>');
  for i := 0 to ViewObj.wRowCount-1 do
  begin
    XmlFile.WriteLine (indent + '    <row>');
    for j := 0 to ViewObj.wColumnCount-1 do
    begin
      // Get the text representation of the cell value
      CellText := ViewObj.wValue[i, j].ToString.OleValue;
      CellText := ReplaceSpecialChars (CellText); // Replace special characters
      XmlFile.WriteLine (indent + '      <cell>' + CellText + '</cell>');
    end;

    // Check if the row has child data
    if (ViewObj.wChildViewCount[i] > 0) then
    begin
      // Export child views
      XmlFile.WriteLine (indent + '      <childviews>');
      for j := 0 to ViewObj.wChildViewCount[i]-1 do
        ExportView (ViewObj.wChildView[i, j], XmlFile, indent + '        ');
      XmlFile.WriteLine (indent + '      </childviews>');
    end;

    XmlFile.WriteLine (indent + '    </row>');
  end;
  XmlFile.WriteLine (indent + '  </rows>');

  // Write the closing tag
  XmlFile.WriteLine (indent + '</view>');
end;

function ReplaceSpecialChars (str);
var s : OleVariant;
begin
  s := aqString.Replace (str, '&', '&amp;', true);
  s := aqString.Replace (s, '<', '&lt;', true);
  s := aqString.Replace (s, '>', '&gt;', true);
  s := aqString.Replace (s, '"', '&quot;', true);
  s := aqString.Replace (s, '''', '&apos;', true);
  Result := s;
end;

C++Script, C#Script

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

  // Obtain the application process and its main form
  p = Sys["Process"]("GridMainDemo");
  frmMain = p["WinFormsObject"]("frmMain");

  // 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");

  // Export the grid contents to an XML file
  FileName = "C:\\GridData.xml";
  ExportToXml (Grid, FileName);
  Log["File"](FileName, "Exported grid data.");
}

function ExportToXml (GridOrView, FileName)
{
  Indicator["PushText"]("Exporting the grid data to a file...");

  // Create a text file and open it for writing
  var Overwrite = true;
  var Unicode = true;
  var fso = new ActiveXObject ("Scripting.FileSystemObject");
  var XmlFile = fso["CreateTextFile"](FileName, Overwrite, Unicode);

  // Write the root tag
  XmlFile["WriteLine"]("<grid>");
  ExportView (GridOrView, XmlFile, "  ");
  // Close the root tag
  XmlFile["WriteLine"]("</grid>");

  // Close the file
  XmlFile["Close"]();

  Indicator["PopText"]();
}

function ExportView (ViewObj, XmlFile, indent)
{
  var ViewCaption, ColCaption, i, j, CellText;

  // Write the opening tag
  ViewCaption = ReplaceSpecialChars (ViewObj["wViewName"]);
  XmlFile["WriteLine"](indent + "<view caption=\"" + ViewCaption + "\">");

  // Write column captions
  XmlFile["WriteLine"](indent + "  <columns>");
  for (i = 0; i < ViewObj["wColumnCount"]; i++)
  {
    ColCaption = ReplaceSpecialChars (ViewObj["wColumn"](i));
    XmlFile["WriteLine"](indent + "    <column>" + ColCaption + "</column>");
  }
  XmlFile["WriteLine"](indent + "  </columns>");

  // Iterate through data rows/cards and export their data
  XmlFile["WriteLine"](indent + "  <rows>");
  for (i = 0; i < ViewObj["wRowCount"]; i++)
  {
    XmlFile["WriteLine"](indent + "    <row>");
    for (j = 0; j < ViewObj["wColumnCount"]; j++)
    {
      // Get the text representation of the cell value
      CellText = ViewObj["wValue"](i, j)["ToString"]()["OleValue"];
      CellText = ReplaceSpecialChars (CellText); // Replace special characters
      XmlFile["WriteLine"](indent + "      <cell>" + CellText + "</cell>");
    }

    // Check if the row has child data
    if (ViewObj["wChildViewCount"](i) > 0)
    {
      // Export child views
      XmlFile["WriteLine"](indent + "      <childviews>");
      for (j = 0; j < ViewObj["wChildViewCount"](i); j++)
        ExportView (ViewObj["wChildView"](i, j), XmlFile, indent + "        ");
      XmlFile["WriteLine"](indent + "      </childviews>");
    }

    XmlFile["WriteLine"](indent + "    </row>");
  }
  XmlFile["WriteLine"](indent + "  </rows>");

  // Write the closing tag
  XmlFile["WriteLine"](indent + "</view>");
}

function ReplaceSpecialChars (str)
{
  var s;
  s = aqString["Replace"](str, "&", "&amp;", true);
  s = aqString["Replace"](s, "<", "&lt;", true);
  s = aqString["Replace"](s, ">", "&gt;", true);
  s = aqString["Replace"](s, "\"", "&quot;", true);
  s = aqString["Replace"](s, "'", "&apos;", true);
  return s;
}

Note that to export the XtraGrid data, you can also use the grid’s built-in methods. For more information on this feature, refer to the XtraGrid Suite documentation.

See Also

Working With Developer Express XtraGrid
Accessing Views in Developer Express XtraGrid
wRowCount Property (Grid Controls)
wGroupCount Property (Grid Controls)
wChildViewCount Property (Grid Controls)

Highlight search results