我将此代码用于与搜索文本框中的文本匹配的焦点行。现在我如何使用%like%criteria for this code
foreach (DataGridViewRow row in GdvDetails.Rows)
{
var cellValue = row.Cells["Bunch Component"].Value;
if (cellValue != null && cellValue.ToString() == txtSearch.Text)
{
GdvDetails.Rows[row.Index].DefaultCellStyle.BackColor = Color.Yellow;
}
else
{
GdvDetails.Rows[row.Index].DefaultCellStyle.BackColor = Color.Empty;
}
}
答案 0 :(得分:0)
试试这个
foreach (DataGridViewRow row in GdvDetails.Rows)
{
var cellValue = row.Cells["Bunch Component"].Value;
if (cellValue != null)
{
if ( cellValue.ToString().Contains(txtSearch.Text))
{
GdvDetails.Rows[row.Index].DefaultCellStyle.BackColor = Color.Yellow;
}
else
{
GdvDetails.Rows[row.Index].DefaultCellStyle.BackColor = Color.Empty;
}
}
}