[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 324
  • Last Modified:

Conditional Formating In DataGridView

I have a datagridview that I would like the entire row to be a background of green if the column called Status = "Complete" for that particular row/record.  Thanks in advance..
0
H-SC
Asked:
H-SC
  • 2
  • 2
1 Solution
 
jpaulinoCommented:
You can use this code in the datagridview cellendedit event

If myDataGridView("Status", e.RowIndex).Value = "Complete" Then
  myDataGridView.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Green
Else
  myDataGridView.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.White
End If

jpaulino
0
 
H-SCAuthor Commented:
jpaulino,

I am using tis form for display only and not allowing edits.  I have a timer attached to it to refresh.  I tried puting the code on the timer event but it does not like thr "e", any ideas??
0
 
jpaulinoCommented:
No problem! You can add this to your timer

For Each row As DataGridViewRow In myDataGridView.Rows
If myDataGridView("Status", row.Index).Value = "Complete" Then
  myDataGridView.Rows(row.Index).DefaultCellStyle.BackColor = Color.Green
Else
  myDataGridView.Rows(row.Index).DefaultCellStyle.BackColor = Color.White
End If
Next
0
 
H-SCAuthor Commented:
jpaulino,

Works great!!  Many thanks
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now