?
Solved

detect background color in datagridview cell

Posted on 2010-11-22
5
Medium Priority
?
741 Views
Last Modified: 2012-05-10
I have a datagrid that has different colors on different rows based on criteria found in different sources.  When I click on that datagrid, a detail form opens up.  I want to detect the background color of the row that was clicked on and make my other form background the same color.

So how can I find out what the current background color is set to on a datagridview row?

Thanks!
0
Comment
Question by:cbrown-aps
  • 2
  • 2
5 Comments
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 34193114
Hi,

Try this

        If DataGridView1.SelectedRows.Count > 0 Then
            If DataGridView1.SelectedRows(0).Cells(0).Style.BackColor = Color.Aqua Then
                'Your Code Here
                '....
            End If
        End If
0
 
LVL 13

Expert Comment

by:iHadi
ID: 34193324
Hi

Try the following:

If dataGridView1.SelectedCells.Count > 0 Then
    Dim index as integer = dataGridView1.SelectedCells(0).RowIndex
    Dim c as Color = dataGridView1.Rows(index).DefaultCellStyle.BackColor
    Me.BackColor = c ' for demo only
End If
0
 

Author Comment

by:cbrown-aps
ID: 34197035
This is happening in my mouse down event.   Neither of these are working for me.
Maybe if you saw how I was getting a value to pass to the child it would spark an idea...

 client = DataGridView1.Item(0, rIndex).Value

Any ideas how I could get it from this approach?
0
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 750 total points
ID: 34197309
do you have a particulary reason to use the Mouse Down Event? because you can try using CellClick Event like this

    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick

        If DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.BackColor = Color.Aqua Then
            'Your Code Here
            '....
        End If

End Sub
0
 

Author Closing Comment

by:cbrown-aps
ID: 34197517
The solution achieved my goal however using a different method.

Thanks for great work!
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month17 days, 2 hours left to enroll

864 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