datagridview / search

0
0

how can i put a search textbox, that when I start tip in the box, the datagridview will automatic search for the value, and show and change the color of the row?

  • You must to post comments
0
0

This might a little late for an answer, but I use to search through the DataTable that feeds the grid instead of a direct search within the grid.


string searchText = txtSearch.Text.Trim();
if (searchText != "" && _data != null && _data.Rows.Count > 0)
{
      DataRow[] searchData = _data.Rows.Cast()
.Where(r => r.ItemArray.Any(
c => c.ToString().IndexOf(searchText, StringComparison.OrdinalIgnoreCase) > 0
)).ToArray();
      grdReceivingLogs.DataSource = searchData.CopyToDataTable();
}
else
      grdReceivingLogs.DataSource = _data;

  • You must to post comments
0
0

Thanks

  • You must to post comments
0
0

Hi,

we can´t do the coding for you but here are some pointers:

  • Attach to the KeyDown event of the TextBox
  • Iterate through all DataGridView.Rows and compare the cells with whatever pattern you want to match the
  • Set/Reset the Background Color of the Rows DefaultCellStyle

Depending on your needs just colorize the first one you find and reset all the others, etc.

Best regards
Frank

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.