Hello,
I am trying to retrieve data from a datagrid. I am using it for automated gui testing in Visual Studio 2010 with C#. When I search a datagrid I have to enter dummy values because when there is one row, the second column displays blank when it is not. The datagrid is third party code and is not standard Microsoft datagrids. I am not sure if this problem is the datagrid or my code. My code I have done is below:
public static List<string> GetDataAllFromSelectedColumn(int columnToRetrieve)
{
// Access UIMap
UIMap UIMap = new UIMap();
// Get the total number of columns, row & cells containing data in table
int totalColumns = GetColumnCount();
int totalRows = GetRowCount();
int totalCells = totalRows * totalColumns;
// Create Uia.Cell object
WpfCustom tableCell = new WpfCustom(UIMap.ACVSClientApplication);
tableCell.SearchProperties.Add("ClassName", "Uia.Cell");
// Click top cell in column
List<int> cellsToClick = ReportLogDataGrid.GetCellsToClick(totalRows, totalColumns);
int iToClick = 1;
// FindMatchingControls - find all controls that are Uia.Cell(s)
UITestControlCollection CellList = tableCell.FindMatchingControls();
Mouse.Click(CellList[columnToRetrieve]);
List<string> tableData = new List<string>();
for (int cell = columnToRetrieve; cell < totalCells + 1; cell = cell + totalColumns)
{
// Ensure cell is visible onscreen to ensure data retrieved correctly
if (cell >= cellsToClick[iToClick])
{
if (iToClick < cellsToClick.Count-1)
{
int cellNumToClick = cellsToClick[iToClick + 1] - 1;
Mouse.Click(CellList[cellNumToClick]);
iToClick = iToClick + 1;
}
}
tableData.Add(CellList[cell-1].Name.ToString());
}
Console.WriteLine("GOT DATA");
List<string> finalTableData = FormatData(tableData, 1);
//return tableData;
return finalTableData;
}
public static List<int> GetCellsToClick(int totalCells, int totalColumns)
{
List<int> pointToClick = new List<int>();
int divisions = totalCells / 20;
for (int i = 0; i < divisions + 1; i++)
{
pointToClick.Add((i * 20) * totalColumns);
}
pointToClick.Add(totalCells * totalColumns);
return pointToClick;
}
public static int GetColumnCount()
{
UIMap UImap = new UIMap();
int iCols = UImap.ACVSClientApplication.UIRecordsTable.ColumnCount;
return iCols;
}
public static int GetRowCount()
{
UIMap UImap = new UIMap();
int iRows = UImap.ACVSClientApplication.UIRecordsTable.RowCount;
return iRows;
}
public static int GetCellCount()
{
int iCells = GetRowCount() * GetColumnCount();
return iCells;
}
Can anyone see where I have went wrong with this code?
Thanks