Disabled Events Still Firing (for DropDownOpened)

3 posts, 1 answers
  1. sculver
    sculver avatar
    11 posts
    Member since:
    Aug 2009

    Posted 31 Aug 2009 Link to this post

    I am developing a solution where I will need to go and pull information dynamically from a web service.

    When the call is complete, I wish to open the drop down so the user will see all the results. However, I also need to run code in the DropDownOpened event as well, and do NOT need it to fire during this time. (I.e., when the user tells it to open, I need to run some code, but when the code auto opens it, I need something else).

    I thought this would be no problem, as I should be able to unsubscribe from the event using the standard -= ????? However, to my surprise, even though I did this, the event still fires.  So for example, if I did this:

    radMyCombo.DropDownOpened -= new EventHandler(MyEventHandler);
    radMyCombo.IsDropDownOpen = true;
    radMyCombo.DropDownOpened += new EventHandler(MyEventHandler);

    I expected this to work, but it did not.  What am I missing????
  2. Answer
    Valeri Hristov
    Valeri Hristov avatar
    2252 posts

    Posted 01 Sep 2009 Link to this post

    Hello Stephen,

    The problem is because the DropDownOpened event is asynchronous, e.g. it is raised in a Dispatcher.BeginInvoce callback. I will check whether this is needed anymore, I remember fixing a problem in an older version this way (I know, it is a bad thing to use Dispatcher), which might be irrelevant now. To workaround the problem I would recommend using a flag:
    - when you populate the combo you rise the flag, then open the dropdown
    - when the dropdown opens, if the flag is raised, do nothing, but lower the flag, otherwise execute the code you need.

    Kind regards,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. sculver
    sculver avatar
    11 posts
    Member since:
    Aug 2009

    Posted 03 Sep 2009 Link to this post

    Thanks, I did the workaround and got it to work.
Back to Top