ListBox don't fire DataRequested anymore, how to restart?

Thread is closed for posting
3 posts, 0 answers
  1. Seznam
    Seznam avatar
    18 posts
    Member since:
    May 2014

    Posted 20 Aug 2014 Link to this post

    In some situation after network error or in other situation
    I can't add data to listbox in DataRequested  event

    But I still need to ListBox to fire this event in feature
    How to handle this state?

    I made this example that generate failure(DataRequested  don't add any items) in random situations
  2. Seznam
    Seznam avatar
    18 posts
    Member since:
    May 2014

    Posted 20 Aug 2014 in reply to Seznam Link to this post

    But I still need ListBox to fire this event in future
    but ListBox simple stop firing this event.
  3. Vladislav
    Vladislav avatar
    277 posts

    Posted 25 Aug 2014 Link to this post

    Hello Martin,

    Thank you for your question.

    The current implementation of the "DataRequested" event of the RadDataBoundListBox, prevents it to be fired again if it fails, i.e. if the data in the "ItemsSource" is not changed. There is a possible "workaround", which consists of adding and immediately removing a "fake" item in order to change the Items collection. We will further investigate this issue in order to find a more proper solution.

    Here is the revisited code for the "neakylist_DataRequested" event handler:

    private void neakylist_DataRequested(object sender, EventArgs e)
                if (DataRequestedActive)
                DataRequestedActive = true;
                //if (rand.Next(0, 1) == 1)
                if (i++ % 2 == 0)
                    //neakylist.DataVirtualizationMode = Telerik.Windows.Controls.DataVirtualizationMode.None;
                    //neakylist.DataVirtualizationMode = Telerik.Windows.Controls.DataVirtualizationMode.OnDemandAutomatic;
                    Items.RemoveAt(Items.Count - 1);
                DataRequestedActive = false;

    I am assuming that you don't actually need to change the DataVirtualizationMode, but if this is intended, you can safely uncomment these lines. Also, please note that
    (rand.Next(0, 1) == 1) returns almost always "false" so it is not reliable example for testing such situation, since the Items collection is not actually changed, although the "DataRequested" event is actually fired. In this code snippet I used a simple counter, which is incremented so the "if" branch is executed and items are actually added to the collection.

    Please don't hesitate to contact us again, if the suggested workaround is not applicable to your scenario or if you encounter some problems with this approach.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top