Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. dataGridView1.SelectionMode = DataGridViewSelectionMode.CellSelect;
  2. string searchValue = "test";
  3.  
  4. int searching = -1;
  5. while (searching < 7)
  6. {
  7. searching++;
  8. try
  9. {
  10. foreach (DataGridViewRow row in dataGridView1.Rows)
  11. {
  12. if (row.Cells[searching].Value.ToString().Equals(searchValue))
  13. {
  14.  
  15. row.Cells[searching].Selected = true;
  16. break;
  17. }
  18. }
  19. }
  20. catch (Exception exc)
  21. {
  22. // MessageBox.Show(exc.Message);
  23. }
  24. }
  25.  
  26. dataGridView1.SelectionMode = DataGridViewSelectionMode.CellSelect;
  27. string searchValue = "test";
  28.  
  29. for (int row = 0; row < dataGridView1.Rows.Count; ++row)
  30. {
  31. for (int col = 0; col < dataGridView1.Columns.Count; ++col)
  32. {
  33. var cellValue = dataGridView1.Rows[row].Cells[col].Value;
  34.  
  35. if (cellValue != null && cellValue.ToString().Equals(searchValue))
  36. {
  37. dataGridView1.Rows[row].Cells[col].Selected = true;
  38.  
  39. // if you want to search every cell for the searchValue then you shouldn't break.
  40. // break;
  41. }
  42. }
  43. }
  44.  
  45. dataGridView1.SelectionMode = DataGridViewSelectionMode.CellSelect;
  46. string searchValue = "test";
  47.  
  48. dataGridView1.Rows.ToList().ForEach(row => row.Cells.ToList().ForEach(cell =>
  49. {
  50. cell.Selected = (cell.Value != null && cell.Value.ToString().Equals(searchValue));
  51. }));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement