I am selecting records in a datagridview using a user input criteria with the code below. However, I am wanting to use multiple search criteria's as the user feels needed. The code I have works, it finds the qualifying records and turns them red, but when I search for another criteria it turns the previous records back to the color black.
And here is the search form code:Code:Private Sub DataGridView1_RowPrePaint(sender As Object, e As DataGridViewRowPrePaintEventArgs) Handles DataGridView1.RowPrePaint If (e.RowIndex < 0 OrElse e.RowIndex = DataGridView1.NewRowIndex) Then Return Dim row = DataGridView1.Rows(e.RowIndex) If (String.IsNullOrEmpty(Filter)) Then row.DefaultCellStyle.ForeColor = Color.Black Else Dim data = DirectCast(DataGridView1.Rows(e.RowIndex).DataBoundItem, DataRowView).Row If data.Field(Of String)(ColumnName).ToLower() _ .StartsWith(Filter.ToLower()) Then row.DefaultCellStyle.ForeColor = Color.Red DataGridView1(0, row.Index).Value = True Else row.DefaultCellStyle.ForeColor = Color.Black End If End If End Sub
Code:Sorter.Filter = ItemToFind Sorter.DataGridView1.Invalidate()




Reply With Quote
