Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

detect background color in datagridview cell

Posted on 2010-11-22
5
Medium Priority
?
739 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

618 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