Trouble with events

Posted by: r3dh2t on 8 September 2017, 1:57 pm EST

  • Posted 8 September 2017, 1:57 pm EST

    Greetings,

     I am having a bit of an odd problem.  I am trying to disable an event for a period of code using the following statement:

    <b>            this.dsdm.Changed -= new FarPoint.Win.Spread.Model.SheetDataModelEventHandler(this.dataModel_Changed); </b>

     This seems to work about 90% of the time, but occasionally this statement doesn't work. 

    I went through it with the debugger, and before this line executes the change event points to this:

    <b>{Method = {Void dataModel_Changed(System.Object, FarPoint.Win.Spread.Model.SheetDataModelEventArgs)}} </b>

    but oddly enough right after this line it says the exact same thing:

     <b>{Method = {Void dataModel_Changed(System.Object, FarPoint.Win.Spread.Model.SheetDataModelEventArgs)}} </b>

    It is almost as if the compiler is ignoring my code to disable the change event.   Can you think of any reasons this might be the case?  I am thoroughly confused.

    Thanks,

    - brad

     

  • Replied 8 September 2017, 1:57 pm EST

    Hello Brad,


    I am not able to replicate the issue, below is the code  snippet that I used to replicate the issue,

    <FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>private</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>void</FONT></FONT><FONT size=2> Form1_Load(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>object</FONT></FONT><FONT size=2> sender, </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>EventArgs</FONT></FONT><FONT size=2> e)


    {


    FarPoint.Win.Spread.Model.</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>ISheetDataModel</FONT></FONT><FONT size=2> isdm;


    isdm = (FarPoint.Win.Spread.Model.</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>ISheetDataModel</FONT></FONT><FONT size=2>)fpSpread1.ActiveSheet.Models.Data;


    isdm.Changed -= </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>new</FONT></FONT><FONT size=2> FarPoint.Win.Spread.Model.</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>SheetDataModelEventHandler</FONT></FONT><FONT size=2>(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>this</FONT></FONT><FONT size=2>.dataModel_Changed);


    isdm.ColumnCount = 5;


    isdm.RowCount = 5;


    isdm.SetValue(2, 2, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>"Model Changed"</FONT></FONT><FONT size=2>);


    }


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>private</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>void</FONT></FONT><FONT size=2> dataModel_Changed(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>object</FONT></FONT><FONT size=2> sender, FarPoint.Win.Spread.Model.</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>SheetDataModelEventArgs</FONT></FONT><FONT size=2> e)


    {


    textBox1.Text = </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>"Model Changed"</FONT></FONT><FONT size=2>;


    }


     


    The dataModel_Changed Event doesnt after removing the Handler.Once the Handler is added the Event does fire again.I tested this code sevreral times.


    Let me know if I missed something.


     


    Regards,


     

    </FONT>
  • Replied 8 September 2017, 1:57 pm EST

    Hi Deepak,

    I'm afraid I was doing something foolish in my code.  Got it fixed!   Thanks.

    - b

     

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels