views:

75

answers:

2

I'm writing a custom DataGridView cell class that hosts a control. I'm listening to the Invalidated event to know whether I should reposition and repaint the cell, but I'm getting loops because repositioning the cell can invalidate other hosted cells, which then invalidate the first one, and so on. I don't want to use a static member to avoid loops, because that won't prevent loops caused by similar but unrelated cell classes, if they were ever used together. So I need to check whether the grid is currently invalidating. How do I do that?

A: 

It sounds like you want to override the Paint member of the DataGridViewCell class, rather than try to listen and respond to Invalidated events. The base class will take care of that for you and provide the graphics object and location information directly to the Paint method

Clyde
I'd like to, but unless I get an answer for http://stackoverflow.com/questions/654330/can-i-have-an-offscreen-control I'm stuck with synchronising the position of the control.
Simon
+1  A: 

You shouldn't have to 'listen' to the invalidated event. When a user control invalidates, onpaint gets called automatically.

There might be a better way to go about solving your ultimate problem (wrt painting your custom datagridview). You could try posting a detailed question about your implementation and asking for some ideas of how to go about it such that you wouldn't have to work around these (seemingly strange) problems.

SnOrfus
Already did - http://stackoverflow.com/questions/225972/how-do-i-host-a-control-in-a-datagridviewcell-for-displaying-as-well-as-editing - got one answer, which was wrong.
Simon