How to get the index of the selectedItem in RadDataBoundListBox

9 posts, 0 answers
  1. Marcus
    Marcus avatar
    24 posts
    Member since:
    Jul 2012

    Posted 26 Jan 2013 Link to this post

    Hi,

    since there is no selectedIndex in the RadDataBoundListBox, could you please provide an example to get the index to use with the wp NavigationService.

    I know it is somehow possible with "indexOf" but a practical example would help here.

    Thanks!

    Best regards,
    Marcus
  2. Todor
    Admin
    Todor avatar
    778 posts

    Posted 28 Jan 2013 Link to this post

    Hi Marcus,

    Thank you for your question.

    Let's say you have a collection of items of type T called Items and this collection is the ItemsSource for a RadDataBoundListBox called listBox. Then here's how you can use IndexOf to get the index of the selected item:
    int index = this.Items.IndexOf(this.listBox.SelectedItem as T);

    Let me know if you need further assistance.

    Greetings,
    Todor
    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. Marcus
    Marcus avatar
    24 posts
    Member since:
    Jul 2012

    Posted 30 Jan 2013 Link to this post

    This one did the trick! Thanks!
  5. Daniel
    Daniel avatar
    9 posts
    Member since:
    Mar 2011

    Posted 14 Feb 2013 Link to this post

    Is there another way to determine the selected index without a reference back to the assigned item collection?
  6. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 19 Feb 2013 Link to this post

    Hi Daniel,

    The other way would be to use RadDataBoundListBox's GetDataSourceItemForDataItem(object dataItem) method. The method returns an object of type IDataSourceItem which has an Index property. Give it a try and let me know how it goes.

    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.
  7. Delilah
    Delilah avatar
    6 posts
    Member since:
    Jan 2013

    Posted 19 Feb 2013 Link to this post

    Not to include SelectedIndex... seriously.
  8. Deyan
    Admin
    Deyan avatar
    2041 posts

    Posted 20 Feb 2013 Link to this post

    Hello Delilah,

    We will extend the API of the control accordingly.

    The lack of a SelectedIndex property is because of some performance considerations we have once when initially developing the concept of the control.

    Greetings,
    Deyan
    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.
  9. FEDERICO
    FEDERICO avatar
    2 posts
    Member since:
    Aug 2013

    Posted 01 Jan 2014 Link to this post

    Hi i can't o get the index of selected item when I use this:

    List<db_autori> Lista_autori = context.db_autori.ToList();
    radlist.ItemsSource = Lista_autori;
     
      private void radlist_ItemTap(object sender, ListBoxItemTapEventArgs e)
            {
              
                int index = this.Lista_autori.IndexOf(this.radlist.SelectedItem as db_autori);
                MessageBox.Show(index.ToString());
              
            }

    it work well if I add item to collection manually

                        radlist.ItemsSource = Lista_autori;
                        db_autori federico = new db_autori();
    Lista_autori.Add(federico);

    how can i get the index of item for the first code??? :I tks
  10. Deyan
    Admin
    Deyan avatar
    2041 posts

    Posted 06 Jan 2014 Link to this post

    Hello Federico,

    Thanks for writing.



    Based on the code you are sharing I cannot exactly say what happens. Can you please open a new support ticket and attach your project so that I can directly debug the code and be able to determine the reason for the undesired behavior.



    Thanks for your time.



    Regards,

    Deyan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINDOWS PHONE 7.

    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
DevCraft banner