Value does not fall within the expected range

2 posts, 0 answers
  1. Gianluca
    Gianluca avatar
    1 posts
    Member since:
    Nov 2013

    Posted 06 Apr 2014 Link to this post

    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.
  2. Deyan
    Deyan avatar
    2026 posts

    Posted 09 Apr 2014 Link to this post

    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.


    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.

  3. DevCraft banner
Back to Top