No SelectedIndex

4 posts, 1 answers
  1. prog1
    prog1 avatar
    61 posts
    Member since:
    Jul 2008

    Posted 19 Jun 2011 Link to this post

    Is there no SelectedIndex property for the DataBoundListBox?
    How should I get it?

    Kind regards
    Fabian
  2. Deyan
    Admin
    Deyan avatar
    2041 posts

    Posted 20 Jun 2011 Link to this post

    Hello Fabian,

    RadDataBoundListBox does not expose a SelectedIndex property by design. We decided that this property is not needed since you can easily acquire the index of the selected item by reading the value of the SelectedItem property and call IndexOf for this item on the source collection.

    Could you please give us some further details about your scenario and why would you need to have this property?

    Thanks for your time.

    Best wishes,
    Deyan
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. DevCraft banner
  4. prog1
    prog1 avatar
    61 posts
    Member since:
    Jul 2008

    Posted 20 Jun 2011 Link to this post

    Hi Deyan,

    event thought of using the RadDataBoundListbox the way you have described but there is one case which will not fit.

    Scenario:
    A list of strings, where item[0] means not set. String for that is "Not set" meaning string.Empty.
    If there is a similar string, which really meant to be "Not set" you will have a problem, because the is no difference between the two objects.

    You could easily make some real objects out of that strings, but that would be more work to be done.

    Kind regards
    Fabian
  5. Answer
    Deyan
    Admin
    Deyan avatar
    2041 posts

    Posted 21 Jun 2011 Link to this post

    Hello Fabian,

    Thanks for writing.

    I am not quite sure that I correctly understand your scenario. Do you mean that you have two strings "Not set" in your collection? If this is the case, this will not work either way - with or without SelectedIndex - since both strings will always be equal and thus the selection mechanism would not differentiate between them.

    Basically, if we add a SelectedIndex property it will be automatically initialized with the index of the currently
    selected item. Therefore, if the selection is not correctly working due to the fact that there are equal items in the source collection, this property will not return the correct selection index as well.

    To solve this case you should simply add a collection of some kind of simple business objects and display a given property exposed on them which might or might not have the same value on different objects. The selection mechanism will differentiate between the different objects by their references.

    I hope this helps.

    Greetings,
    Deyan
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top