代码如下:
for (int i = 0; i < gridView1.DataRowCount; i++)
{
CorpDept empDept = (CorpDept)gridView1.GetRow(i);
if (empDept.deptName.Contains(str))
{
gridView1.FocusedRowHandle = i;
gridControl1.Refresh();
}
}
gridView1为gridControl对应的View,遍历其中数据源,获取每一行的数据,判断相关字段是否符合要求,如果符合要求,则该行数据设置为被选中!
效果如下:(若博文发表时间过长,CSDN会清除图片,如果图片不可见,请见谅!)