I load a text file in a datagridview. The problem is that I want to make some validations to it after I import it.
Eg.
AA / Code / Value
1 1111111 12
2 222222 22
==========
This table contain many rows. What I want to do is when the value in code is in the list of my codes then to leave the value intact else to delete the value.
Because I cannot make this programmatically as I found nothing what I decided to do is to format the datagridview where this contition applies and correct it myself.
This is what I came up to now which is not working. Can you help me please?
Private Sub DGVReport_CellFormatting(ByVal sender As Object, ByVal e As DataGridViewCellFormattingEventArgs) Handles DGVReport.CellFormatting
Dim lookup As New Dictionary(Of Integer, Double)
lookup.ContainsValue(CDbl("540752"))
lookup.ContainsValue(CDbl("8528125810"))
lookup.ContainsValue(CDbl("2207100090"))
lookup.ContainsValue(CDbl("87120030"))
Dim key As Integer = CDbl("Code")
Dim value As Double = lookup(key)
If DGVReport.Columns(e.ColumnIndex).Name.Equals("Code") Then
If CDbl(e.Value).ToString.StartsWith(key) Then
DGVReport.Columns(e.ColumnIndex).Name.Equals("Value") e.CellStyle.BackColor = Color.Pink
e.CellStyle.ForeColor = Color.Red
End If
End If
End Sub
|