Set selected item in DataBoundListBox

5 posts, 1 answers
  1. Kai
    Kai avatar
    6 posts
    Member since:
    Dec 2012

    Posted 30 Dec 2012 Link to this post

    Hi all,

    in DataBoundListBox, how could I set the top item? I have a list with 30 records sorted by creation date. When the listbox is displayed initially, the upcoming record should be displayed at the top. So the user should be able to scroll in both directions (up and down) to see previous and upcoming records. How does that work?
    Thanks!
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 02 Jan 2013 Link to this post

    Hi Kai,

    Thank you for contacting us. Could you please elaborate a bit more on the issue at hand? I'm not sure I fully understand what the problem is. Also, it would be great if you could attach a sample project reproducing the issue. This way we will be better able to assist you. Thank you for your cooperation and understanding.

    Kind regards,
    Kiril Stanoev
    the Telerik team
    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
  3. DevCraft banner
  4. Kai
    Kai avatar
    6 posts
    Member since:
    Dec 2012

    Posted 02 Jan 2013 Link to this post

    Hi Kiril,
    Example is a good idea :-)
    • Start your ExamplesCS_WP.
    • In the emulator go to the 'featured' page.
    • Click on 'DataBound ListBox'

    The emulator shows the top 50 netflix movies. But instead of the Top 1 at the top, the list should display position 10 on start. The user should be able to scroll up (to row 1) and down (to row 50). I've attached a screenshot of the expected start screen.
    Thanks!

  5. Answer
    Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 04 Jan 2013 Link to this post

    Hi Kai,

    Thank you for the clarification. RadDataBoundListBox exposes a method called BringIntoView which is what I believe you're looking for. Let's say you have a DataBoundListBox which displays a list of models called Record:

    <telerikPrimitives:RadDataBoundListBox x:Name="dataBoundListBox1">
        <telerikPrimitives:RadDataBoundListBox.ItemTemplate>
            <DataTemplate>
                <Border Height="75" BorderBrush="LightGray" BorderThickness="0 0 0 2">
                    <TextBlock Text="{Binding Name}" VerticalAlignment="Center" HorizontalAlignment="Left"
                            FontSize="32" />
                </Border>
            </DataTemplate>
        </telerikPrimitives:RadDataBoundListBox.ItemTemplate>
    </telerikPrimitives:RadDataBoundListBox>

    public class Record
    {
        public Record(string name)
        {
            this.Name = name;
        }
        public string Name { get; set; }
    }

    To bring the 12th item into view, you should do the following:

    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            this.Loaded += this.MainPage_Loaded;
        }
     
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            List<Record> records = new List<Record>();
            for (int i = 0; i < 20; i++)
            {
                Record r = new Record("Record #" + i.ToString());
                records.Add(r);
            }
     
            this.dataBoundListBox1.ItemsSource = records;
            this.dataBoundListBox1.BringIntoView(records[11]);
        }
    }

    Give it a try and let me know if it helps your scenario. I'd be glad to assist you further.

    Greetings,
    Kiril Stanoev
    the Telerik team
    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
  6. Kai
    Kai avatar
    6 posts
    Member since:
    Dec 2012

    Posted 09 Jan 2013 Link to this post

    Works great. Thanks Kiril!
Back to Top
DevCraft banner