This is a migrated thread and some comments may be shown as answers.

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

2 Answers 24 Views
DataBoundListBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Seznam
Top achievements
Rank 2
Seznam asked on 20 Aug 2014, 12:33 PM
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
http://live.mdragon.org/telerikListTest.zip

2 Answers, 1 is accepted

Sort by
0
Seznam
Top achievements
Rank 2
answered on 20 Aug 2014, 12:39 PM
But I still need ListBox to fire this event in future
but ListBox simple stop firing this event.
0
Vladislav
Telerik team
answered on 25 Aug 2014, 10:27 AM
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)
        {
            Debug.WriteLine("neakylist_DataRequested");
            if (DataRequestedActive)
            {
                return;
            }
 
            DataRequestedActive = true;
 
            //if (rand.Next(0, 1) == 1)
            if (i++ % 2 == 0)
            {
                Items.Add("asdfasdfasd");
            }
            else
            {
                //neakylist.DataVirtualizationMode = Telerik.Windows.Controls.DataVirtualizationMode.None;
                //neakylist.DataVirtualizationMode = Telerik.Windows.Controls.DataVirtualizationMode.OnDemandAutomatic;
                Items.Add(string.Empty);
                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.

Regards,
Vladislav
Telerik
 

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.

 
Tags
DataBoundListBox
Asked by
Seznam
Top achievements
Rank 2
Answers by
Seznam
Top achievements
Rank 2
Vladislav
Telerik team
Share this question
or