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

I am trying to show an image in row header text based on certain condition.Here's my requirement

First i select an excel file, which is displayed in datagridview. Then when i click submit button these excel values are inserted row by row.

If first row is inserted successfully, i want to show an image @ that row header,
if it fails then another image and so on.


How can i achieve this.. Pls help me. By the way its windows form :)
Posted
Updated 26-Mar-14 1:16am
v2

1 solution

I'd try subscribing to the CellPainting[^] event. Within its handler method, you can perform any conditional checks you want. And within its arguments[^] you get a Graphics[^] object to draw whatever fits your need.

I haven't tried whether that works for heading cells, though.
 
Share this answer
 
v2
Comments
Arjun Menon U.K 26-Mar-14 8:54am    
But how can i call the event during the datatable looping?
lukeer 26-Mar-14 8:59am    
You don't.
The event gets called when the DataGridView is painted to the screen. Whatever information is necessary for it to succeed, you have to have it alrady stored somewhere in advance.
So during database operation, you collect and store data. On painting, the CellPainting event handler uses the stored data to decide if and what to draw.
Arjun Menon U.K 26-Mar-14 9:07am    
From what you have said, i thnk this is it. I declare a global list say a dictionary for each row. Then while the datatable containing the excel values are looped and saved in DB , the result is stored in the dictionary. But what i do want to know is that whether the cell painting is called automatically again after the db process? anyways i will try.datagrid.refresh, causes only its repainting rt?
lukeer 27-Mar-14 5:08am    
No, it's not called automatically. You have to either call Refresh()[^] or Invalidate()[^] on the DataGridView[^]. The latter should be preferred because it doesn't interfere with the normal repainting schedule. It just tells the OS that the DataGridView needs to be repainted and OS decides when there's time to do that. Usually that's soon enough plus the advantage of causing one repaint for multiple calls to Invalidate() whereas Refresh() is executed every time.
Arjun Menon U.K 27-Mar-14 7:59am    
Sure thing.. THanks buddy

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