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

How to get the index of the selectedItem in RadDataBoundListBox

8 Answers 174 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.
Marcus
Top achievements
Rank 2
Marcus asked on 26 Jan 2013, 09:42 PM
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

8 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 28 Jan 2013, 11:53 AM
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.
0
Marcus
Top achievements
Rank 2
answered on 30 Jan 2013, 09:04 AM
This one did the trick! Thanks!
0
Daniel
Top achievements
Rank 1
answered on 14 Feb 2013, 06:01 PM
Is there another way to determine the selected index without a reference back to the assigned item collection?
0
Kiril Stanoev
Telerik team
answered on 19 Feb 2013, 09:19 AM
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.
0
Delilah
Top achievements
Rank 1
answered on 19 Feb 2013, 02:16 PM
Not to include SelectedIndex... seriously.
0
Deyan
Telerik team
answered on 20 Feb 2013, 12:50 PM
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.
0
FEDERICO
Top achievements
Rank 1
answered on 01 Jan 2014, 09:24 AM
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
0
Deyan
Telerik team
answered on 06 Jan 2014, 08:46 AM

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 >>
Tags
DataBoundListBox
Asked by
Marcus
Top achievements
Rank 2
Answers by
Todor
Telerik team
Marcus
Top achievements
Rank 2
Daniel
Top achievements
Rank 1
Kiril Stanoev
Telerik team
Delilah
Top achievements
Rank 1
Deyan
Telerik team
FEDERICO
Top achievements
Rank 1
Share this question
or