我想单击WinTable中符合我的条件但到目前为止无法成功的确切行。我可以搜索确切行的条件,但无法获取总行数,因此我将为所有行进行循环。我尝试了collection和table.Rows.Count,但是两者都没有给我带来任何好处。有人可以帮我吗?
#region Variable Declarations
WinTable uIG1Table = this.UIProMANAGEWindow.UIDefinitionsWindow.UIG1Window.UIG1Table;
WinRow dataGridrow = uIG1Table.GetRow(0);
#endregion
UITestControlCollection rows = uIG1Table.Rows;
// MessageBox.Show(rows[5].RowIndex.ToString());
foreach (WinRow row in uIG1Table.Rows)
{
foreach (WinCell cell in row.Cells)
{
if (cell.Value.ToString() == "E81")
Mouse.Click(cell, new Point(5, 0));
}
}
这是for循环的代码
int rows = uIG1Table.Rows.Count;
for (int i = 0; i < rows; i++)
{
foreach (WinCell cell in dataGridrow.Cells)
{
if (cell.Value.ToString() == "E81")
Mouse.Click(cell, new Point(5, 0));
}
}
答案 0 :(得分:0)
连续执行GetChildren()
时,您会注意到第一个孩子的类型为RowHeader
。用户通常单击行标题以选择行。
以下代码将迭代DataGridView
中的所有行,然后单击行标题,从而有效地选择行:
UITestControlCollection rows = YourUIMapTable.Rows;
foreach (UITestControl row in rows)
{
UITestControl rowHeader = row.GetChildren().Single(child => child.ControlType == ControlType.RowHeader);
Mouse.Click(rowHeader);
}
如果要选择特定的行,可以执行以下操作:
Mouse.Click(YourUIMapTable.Rows[putIndexNumberHere].GetChildren().Single(child => child.ControlType == ControlType.RowHeader));
上面的示例代码基于我在回答此问题时编写的程序: How to get cell color information of a WinCell with codedui?