我有一个 DataGridView,我正在输入一个列表
DataGridView 正在完美填充,但我希望现在能够在网格(任何列)中搜索用户输入的值。
我一直在试图潜入解决方案,但我找不到 DataGridView.Cells[X,Y] 类型的属性。
我试过这个:
String searchVal = textBoxValueToFindInGrid.Text.Trim();
for (int i = 0; i < dataGridViewPlatypusElements.RowCount; i++)
{
for (int j = 0; j < dataGridViewPlatypusElements.ColumnCount; j++) {
if (dataGridViewPlatypusElements.Text.Contains(searchVal))
{
dataGridViewPlatypusElements.GoTo*(Cells[j,i]);
}
}
}
。但是,当然,DataGridView.Text 不包含任何有用的内容。这是我需要 Cells[X,Y] 属性的地方。
- 在这种情况下,我不认为它是有害的。
可能对其他有类似问题的人有用:
if(dataGridView.Rows[i].Cells[j].Value.ToString().Contains(searchText)
{
dataGridView.Rows[i].Cells[j].Selected = true;
}
如果需要有关单元格的详细信息,可以遍历所选单元格:
foreach(DataGridViewCell selectedCell in dataGridView.SelectedCells)
{
..........
}
怎么样
dataGridView.Rows[X].Cells[Y].Value