Link to home
Start Free TrialLog in
Avatar of cbrown-aps
cbrown-aps

asked on

detect background color in datagridview cell

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!
Avatar of gamarrojgq
gamarrojgq

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
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
Avatar of cbrown-aps

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of gamarrojgq
gamarrojgq

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The solution achieved my goal however using a different method.

Thanks for great work!