I have One DatagridView.
I need to highlights rows which belongs to "ID"
For Example
ID
1
1
1
1
2
2
2
3
That's it.
I need to highlights ID-1 all rows to Yellow Color
Then 2 to Lime Color.
And 3 to Yellow Again.
Here is my Code But Not working. Any Help will be really appreciated.
For i As Integer = 0 To dgvvoucher.Rows.Count - 1
For j As Integer = 0 To dgvvoucher.Rows.Count - 1
If dgvvoucher.Item(0, i).Value = dgvvoucher.Item(0, i).Value Then
dgvvoucher.Rows(i).DefaultCellStyle.BackColor = Color.Yellow
Else
dgvvoucher.Rows(i).DefaultCellStyle.BackColor = Color.Lime
End If
Next
Next
zabayin
0
Newbie Poster
Recommended Answers
Jump to PostBelieve it or not there is also a DataGridView.AlternatingRowsDefaultCellStyle Property
Jump to PostDid the link did not provide one?
Perhaps this is all you need.
Jump to PostPerhaps try something like this:
// walk through rows of dgv with for-loop if (Convert.ToInt32(row.Cells[0].Value) == 1) //ID of first column equals 1 { row.DefaultCellStyle.BackColor = Color.Red; } else if(Convert.ToInt32(row.Cells[0].Value) == 1) { row.DefaultCellStyle.BackColor = Color.Green; }
All 9 Replies
ddanbe
2,724
Professional Procrastinator
Featured Poster
zabayin
0
Newbie Poster
ddanbe
2,724
Professional Procrastinator
Featured Poster
zabayin
0
Newbie Poster
zabayin
0
Newbie Poster
ddanbe
2,724
Professional Procrastinator
Featured Poster
ddanbe
2,724
Professional Procrastinator
Featured Poster
zabayin
0
Newbie Poster
zabayin
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.