Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good Day , I have Transactions DGV that holding Same Transaction ID for both type (Buy /Sell). This is on Cell(0) of the DGV. I want to highlight the transaction that bought but not sold , Cell(1) has the transaction type. I have tried the below code but it is highlighting all the rows 


What I have tried:

For i As Integer = 0 To DGV_Trans.Rows.Count - 2
            For j As Integer = i + 1 To DGV_Trans.Rows.Count - 2

                If DGV_Trans.Rows(i).Cells(0).Value <> DGV_Trans.Rows(j).Cells(0).Value Then
                    DGV_Trans.Rows(j).DefaultCellStyle.BackColor = Color.Green

                End If

            Next
        Next
Posted
Updated 31-May-20 19:10pm
Comments
Maciej Los 1-Jun-20 2:20am    
What values holds dgv?
qulaitks 1-Jun-20 2:25am    
DGV cell(0) holds int values and Cell (1) bit. Regards
Maciej Los 1-Jun-20 5:58am    
Not helpful at all... You should share sample data (use "Improve question widget") and paste it as a text.

BTW: use "Reply" widget (near the nick/login).

1 solution

You could use the CellFormatting event:
VB.NET
Private Sub DGV_Trans_CellFormatting(ByVal sender As Object, ByVal e As EventArgs) Handles DGV_Trans.CellFormatting

   Dim row As DataGridViewRow = DGV_Trans.Rows(e.RowIndex)
   If (row.Cells(1).Value = "Buy")
      row.Cells(e.ColumnIndex).BackColor = Color.Green
   End If

End Sub
 
Share this answer
 
v2
Comments
qulaitks 1-Jun-20 1:39am    
Thanks for the reply, the above code will highlight all cells in DGV the have "Buy" Value. What I wand is to compare the Cell(0) rows value if no matched value the look into cell (1) for "Buy" or "Sell" . Best Regards

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900