Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to change all DataGridView rows style (like back color), if they have specific value?

Posted on 2012-08-29
3
Medium Priority
?
732 Views
Last Modified: 2012-08-29
I'm trying to change DataGridView rows style, background color, on load, and if each row specific value.
With below code, I'm able to change background color. And, next code I'm able to get cell value of each row.

DataGridView rows, and column(0) has values 0,1, or 2.

I would like to get
- if all DataGridView Rows has value 0, then background color is lightblue.  
- if all DataGridView Rows has value 1, then background color is lightgreen.
- etc...  



'change row color
    Dim style0 As New DataGridViewCellStyle()
    style0.BackColor = Color.lightblut
    DataGridView1.Rows(0).DefaultCellStyle = style0

'read row values
  Dim gridrowcounts As Integer = DataGridViewRezervacije.Rows.Count - 2
        Dim i As Integer
        For i = 0 To gridrowcounts
            Dim gridrows = DataGridViewRezervacije.Rows(i).Cells(0).Value.ToString()
            MsgBox(gridrows)
        Next

Open in new window


Thank you in advance for help.
0
Comment
Question by:dejandejanovic
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 38345360
Try

    Dim style0 As New DataGridViewCellStyle()
    style0.BackColor = Color.lightblut

'read row values
  Dim gridrowcounts As Integer = DataGridViewRezervacije.Rows.Count - 2
        Dim i As Integer
        For i = 0 To gridrowcounts
           If DataGridViewRezervacije.Item(columnindex, i).value = 0 then
                DataGridViewRezervacije.Rows(i).DefaultCellStyle = style0
           End If
        Next
0
 

Author Closing Comment

by:dejandejanovic
ID: 38345428
Works perfect. Thank you...
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38345502
Glad to help :-)
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question