Cornelius
Cornelius

Reputation: 1027

Pass DataGridView cell BackColor to variable for later use in c#

Project info: Windows Application in c#, .net 4.0

I'm working on a form with a DataGridView, this dgv has pre-established cell BackColors from an earlier function in the application.

I'm adding a new private void function that checks a quantity column in this DataGridView, this new function will highlight cells for the qty column where the qty values match a certain criteria.

In my loop, where I check the data in the DataGridView, I need to capture the existing BackColor so I can set it back to that existing color, if the qty value does not match my criteria.

I'm using a foreach (DataGridViewRows r in myDGV.Rows) loop to check the cells in my DataGridView, how can I capture the existing BackColor of my cells inside this loop?

Upvotes: 0

Views: 101

Answers (1)

KC-NH
KC-NH

Reputation: 748

The row, r, has a Cells property and each cell has a Style property. One part of the style is the BackColor. Does that help? If not, please explain more about what you're trying to do.

Upvotes: 0

Related Questions