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

Value does not fall within the expected range

1 Answer 58 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.
Gianluca
Top achievements
Rank 1
Gianluca asked on 06 Apr 2014, 06:03 PM
I wrote this code to add items to RadDataBoundListBox.

// Dati.nomiDiLang <--- It's a List<string>
 
        ObservableCollection<Grid> lstDaAddToLstLangSugg = new ObservableCollection<Grid>(); int x = 0;
        foreach (object item in Dati.nomiDiLang)
        {
            Grid griglia = new Grid(); griglia.Height = 40; griglia.Width = 350; griglia.Name = x.ToString();
            TextBlock labelTesto = new TextBlock();
            labelTesto.Width = 300; labelTesto.Height = 25; labelTesto.TextWrapping = TextWrapping.NoWrap; labelTesto.FontSize = 22; labelTesto.Margin = new Thickness(5, -5, 0, 0);
 
            labelTesto.Text = item.ToString(); griglia.Children.Add(labelTesto);
            lstDaAddToLstLangSugg.Add(griglia); x++;
        }  lstLangSugg.ItemsSource = lstDaAddToLstLangSugg;


It works correctly, but when I scroll to the last item and then go back to the first app crashes producing not only this: "Value does not fall Within the expected range."
I've added 237 items.

1 Answer, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 09 Apr 2014, 08:39 AM
Hello Gianluca,

Thanks for writing and for the code snippet.

You should not be using a collection of Visual Elements as a source for the DataBoundListBox instance. The common pattern is to prepare a collection of business objects, assign it as a source and define a DataTemplate  which defines how items are visualized in the control. Take a look at the DataBoundListBox examples in our Telerik Examples solution (source is installed with the controls).

I hope this helps.

Regards,
Deyan
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
Gianluca
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Share this question
or