Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gettting datagrid cell color...

Status
Not open for further replies.

netKID

Programmer
Mar 5, 2004
9
US
I have a datagrid which has some logic to color the cells and I got it colored. Now the problem for me is I want to write this to an EXCEL and while doing so I want to keep the cell color as well.

So my question is how do I get a datagrid cell backcolor/forecolor? I tried using TableStyle(0).GridColumnStyles but I could not find a property which gives the color of a particular cell on a particular row.

Any help or link would be nice.
 
I may be wrong, but I had to use a derived class of the datagridtextbox to color my cells. If I had to find out the color, I would just save it in a variable somewhere.
 
Thanks for the reply. I am using a gridTextBoxColumn derived class to color my cell. But I have around 15 columns (and 1000+ rows) and each has different colors depending on the situation. So declaring a variable and storing the value won't be a direct and feasible approach for me.

Thanks
 
How are you colouring the cell ? I'm guessing that you are overriding the Paint event in your custom column style, in which case your options are limited:

1. Create an array with the same dimensions as the source table and store the cell colour in the relevant array element when painting.

2. Ensure the cell is visible, retrieve the location, create a bitmap of the cell then use Bitmap.GetPixel to get the colour of a suitable pixel (e.g. top left).
 
I think SHelton has the right idea.

Question to ponder: Does not the grid keep the colors of the cells somewhere?

Hey netKID, can you please post your derived class of the datagridtextbox? I am also doing this, and I'd like to see your version. Maybe I can help further.
I may be doing something you are not, or vise-versa.

Thanks

Gary
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top