Solved

detect background color in datagridview cell

Posted on 2010-11-22
5
735 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 250 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 Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with opening combobox using VB.NET. 3 34
VS 2017 18 101
SSRS Deployment problem 5 91
VB.Net SQL Query 2 Tables Different Databases 3 43
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

713 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