Simon
Simon

Reputation: 25983

How do I find out whether a control is currently invalidating?

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?

Upvotes: 0

Views: 256

Answers (2)

Steven Evers
Steven Evers

Reputation: 17196

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.

Upvotes: 1

Clyde
Clyde

Reputation: 8145

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

Upvotes: 0

Related Questions