Disabling an event

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dom

    Disabling an event

    In a DataGridView, I allow the user to change a cell, which fires the
    CellValueChange d 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 CellValueChange d event is fired a second time.

    I want to do the following:

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

    In EndCellEdit ...
    [Turn on the CellValueChange d 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 DataGridViewCel lEventHandler (ProcName);
    x.CellValueChan ged -= m_Event
    x.CellValueChan ged += m_Event

    Is one way better / safer than the other?

    Dom

  • Marc Gravell

    #2
    Re: Disabling an event

    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

    Comment

    Working...