Disabling an event

D

Dom

In a DataGridView, I allow the user to change a cell, which fires the
CellValueChanged event (which I use to validate the cell contents),
followed by the EndCellEdit event, which I use to doctor the entry
(eg, change to upcase, etc). The problem is that when I doctor the
cell contents, the CellValueChanged event is fired a second time.

I want to do the following:

In CellClick ...
[Turn off the CellValueChanged event]
BeginEdit (true);

In EndCellEdit ...
[Turn on the CellValueChanged event]
doctor the contents

The question is, how do I turn off an event. I can think of two ways;

1. Use a flag.
2. m_Event = new DataGridViewCellEventHandler (ProcName);
x.CellValueChanged -= m_Event
x.CellValueChanged += m_Event

Is one way better / safer than the other?

Dom
 
M

Marc Gravell

Well, the first would be quicker... the second involves lots of
delegate operations (delegates are immutable, so += and -= involve
creating new extended/abbreviated multi-cast delegates).

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top