Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a small doubt in coloring datagridview.

I already know how to color a particular row/column, but I didn't know how to color a cell when the item quantity become less than 10.

Can anybody help me

Thanks in advance
Posted
Updated 16-Jan-11 21:51pm
v3
Comments
Dalek Dave 17-Jan-11 3:51am    
Edited for Readability.

See Accepted answer in THIS[^] thread, would be quite helpful as they also targeting cell color on specific condition.
 
Share this answer
 
Comments
sevenbell 17-Jan-11 4:04am    
Thanks
Nuri Ismail 17-Jan-11 4:09am    
Hiren, I suspect the OP doesn't know that 1 and 2 are down-votes (he down-voted my answer too). :)
Your answer is very good, have a 5 for compensation. :)
Hiren solanki 17-Jan-11 4:10am    
Thank Nuri.
sevenbell 17-Jan-11 6:16am    
I already accepted your code and leave a thanks 2 hrs ago.
 
Share this answer
 
You can use the Style[^] property of DataGridViewCell class. Here is a quick example:
C#
// Set the background color of specified cell 
theDataGridView.Rows[i].Cells[j].Style.BackColor = System.Drawing.Color.Red;


[UPDATE - after OP comment]
If you need to change the color of cell, dynamically, based on its value you can use DataGridView.CellFormatting Event[^] (the answer from Hiren contains a link to similar approach). The example from the documentation page shows how to change the background color of a cell, based on the string entered in it. It should not be a problem to use similar approach in your case. If there are some problems, please let me know.
[/UPDATE]
 
Share this answer
 
v7
Comments
Nuri Ismail 17-Jan-11 4:30am    
Dear OP,

Can you tell me please, what was so wrong with my answer?
You asked how to change the color of a specific sell and I gave you a concrete example.
If this is not helpful for you at least leave a comment so I'll improve my answer.

Thank you
sevenbell 17-Jan-11 6:11am    
oh no I voted you before adding any comment my network become down.Iam ectremely sorry If it hurt you.your code will work for a particular row by indicating its index like 1 or 2 . but i need the code that change the color of the less quantity without indicating a particular row. because in a Table there may have many items . please help me to change the columns of less quantity cells
Nuri Ismail 17-Jan-11 8:05am    
No problem, down-votes are welcome if they come with motivation. Please see my updated answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900