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

Set selected item in DataBoundListBox

4 Answers 65 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.
Kai
Top achievements
Rank 2
Kai asked on 30 Dec 2012, 05:04 PM
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!

4 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 02 Jan 2013, 02:24 PM
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.
0
Kai
Top achievements
Rank 2
answered on 02 Jan 2013, 05:08 PM
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!

0
Accepted
Kiril Stanoev
Telerik team
answered on 04 Jan 2013, 08:48 AM
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.
0
Kai
Top achievements
Rank 2
answered on 10 Jan 2013, 01:20 AM
Works great. Thanks Kiril!
Tags
DataBoundListBox
Asked by
Kai
Top achievements
Rank 2
Answers by
Kiril Stanoev
Telerik team
Kai
Top achievements
Rank 2
Share this question
or