【发布时间】:2017-09-16 16:16:52
【问题描述】:
我有 1 个文本框和 1 个网格,我想使用文本框使用按键事件搜索动态数据,并在网格中突出显示我要搜索的那个词。
【问题讨论】:
-
您的问题可能在其他地方得到了解答。请查看其他问题并在发布问题之前搜索网络。
我有 1 个文本框和 1 个网格,我想使用文本框使用按键事件搜索动态数据,并在网格中突出显示我要搜索的那个词。
【问题讨论】:
将 OnKeyPress 事件附加到您的 TextBox 并在该事件中编写您的逻辑。
private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
{
string value = TextBox.Text;
foreach(GridViewRow row in GridView.Rows)
{
for(int i = 0; i < GridView.Columns.Count; i++)
{
string cellText = row.Cells[i].Text;
if(cellText == value)
{
// Highlights the entire row
row.DefaultCellStyle.SelectionBackColor = Color.Yellow;
break;
}
}
}
}
【讨论】: