/// <summary> /// Look through the datagridview for the matching string /// </summary> /// <param name="StartIndex">The starting location</param> /// <param name="EndIndex">The final location</param> /// <param name="SearchString">The search paramater</param> private void SearchDGV(int StartIndex, int EndIndex, string SearchString) { // Iterate through DGV rows, from StartIndex to EndIndex of DGV for (int RowIndex = StartIndex; RowIndex < EndIndex; RowIndex++) { bool MatchFoundInCell = false; // Iterate through each cell of current row (RowIndex) and check for a match foreach (DataGridViewCell CellValue in DgvVoorraad.Rows[RowIndex].Cells) { // Ignore checkboxes if (CellValue.GetType() == typeof(DataGridViewCheckBoxCell)) { continue; } // If match is found, set matchFoundInCell to true; if (CellValue.Value.ToString().ToLower().Contains(SearchString.ToLower())) { if (CellValue.Visible == true) { MatchFoundInCell = true; } } } // Highlight each cell in a row if it a match was found if (MatchFoundInCell == true) { MatchFound = true; MatchesFound += 1; // Change cell BackGround Color foreach (DataGridViewCell CellValue in DgvVoorraad.Rows[RowIndex].Cells) { CellValue.Style = FoundMatchCellStyle; } // Continue searching or stop search at current match if (FindAllMatches == false && MatchFoundInCell == true) { DgvVoorraad.ClearSelection(); DgvVoorraad.Rows[RowIndex].Selected = true; DgvVoorraad.CurrentCell = DgvVoorraad.Rows[RowIndex].Cells[0]; } } } }