Dynamic ListBoxes

4 posts, 0 answers
  1. Tomas
    Tomas avatar
    3 posts
    Member since:
    Nov 2013

    Posted 12 Nov 2013 Link to this post

    Hi everybody,

    I need to solve the following problem: I have a dynamic set of properties (ObservableCollections of strings or integers) and for each of them I need to create a listbox. I have succeeded creating listboxes, however I cannot select items, I cannot scroll the content etc.

    The code generating the list box follows:
    private UIElement GetRadListBox(int number, string block)
            {
                var lb = new Telerik.Windows.Controls.ListBox();
                lb.Name = string.Format(DYNAMIC_SELECTOR_NAME_FORMAT, block, number.ToString("00"));
                lb.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                lb.SelectionMode = Telerik.Windows.Controls.SelectionMode.Multiple;
                lb.Width = 240;
                lb.MaxHeight = 300;
                // bind item source
                var binder = new Binding(string.Format(DYNAMIC_LIST_PROPERTY_FORMAT, block, number.ToString("00")));
                binder.Mode = BindingMode.TwoWay;
                lb.SetBinding(Telerik.Windows.Controls.ListBox.ItemsSourceProperty, binder);
                lb.ItemsPanel = (ItemsPanelTemplate)Resources["VirtualizingStackPanelTemplate"];
     
                return lb;
            }

    The returned element is added as a child to a StackPanel.

    I would appreciate any help.
  2. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 14 Nov 2013 Link to this post

    Hi Tomas,

    Try replacing the ListBox with RadListBox and everything should start working as expected:

    ...
    // var lb = new Telerik.Windows.Controls.ListBox();
    var lb = new Telerik.Windows.Controls.RadListBox();
    ...

    The first ListBox is obsolete and shouldn't be used any more, the correct one is RadListBox.

    Hope this helps.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
  4. Tomas
    Tomas avatar
    3 posts
    Member since:
    Nov 2013

    Posted 15 Nov 2013 Link to this post

    Hi Kalin,
    thanks for the tip, but there is no RadListBox in the Telerik Controls library I have. Any ideas?
  5. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 15 Nov 2013 Link to this post

    Hi Tomas,

    The RadListBox should be present in the Telerik.Windows.Controls assembly as you can see in the Controls Dependencies article from our online help documentation. If you don't have it you are probably using old version and we recommend that you upgrade to the newest Q3 2013 version of the controls.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top