【发布时间】:2017-05-03 13:03:42
【问题描述】:
如何根据 textbox2 中的值突出显示数据网格行?
最终,当在第 2 列中找到匹配值时,相应行上的 QTY 字段(第 3 列)需要为最终用户扫描的每个 QR 码更改 -1。一旦 QTY 值达到 0,该行将需要突出显示为绿色。
我不能让它工作已经尝试了几种不同的方式来编写 foreach 部分,但没有运气
我的代码如下:
private void textBox2_KeyPress(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
iCBOMHDataGridView.DataSource = iCBOMHBindingSource;
string input = textBox2.Text;
string output = "";
textBox2.Text = Regex.Replace(input, @"^\d{4}|[A-z]{2}[0-9]{5},|,|,|\d{|[0-9]{4}/....|\d{1,}\/\d{2,2}\/\d{4}|\s.........|\s|,|,|,|\d*?.$|[*?:/]\n|\r|\r\n", output);
foreach (DataGridViewRow row in iCBOMHDataGridView.Rows)
{
if ((string)row.Cells[2].Value == textBox2.Text)
{
row.Selected = true;
}
else
{
row.Selected = false;
MessageBox.Show("Part Number doesn't match");
}
}
}
}
【问题讨论】: