按照代码过滤条件%,如%

时间:2014-11-14 07:32:01

标签: c# datagridview

我将此代码用于与搜索文本框中的文本匹配的焦点行。现在我如何使用%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;
      }
}

1 个答案:

答案 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;
  }
}
}