CommandBarDropDownList FindItem

4 posts, 0 answers
  1. Xander
    Xander avatar
    12 posts
    Member since:
    Jan 2010

    Posted 01 Mar 2011 Link to this post

    Hello, it there any way how to find CommandBarDropDownList Item by string value?
    I need following functionality. but I miss FindItem function.
    CommandBarDropDownList c = new CommandBarDropDownList();
    c.SelectedItem = c.FindItem("b");

    Only way I know is to loop over c.Items and check, but I expect some easier way in components for commandbars (and it was also included in RadToolStrip and is in standard MS).

    Thanks for any help, I had to overlook it somewhere, but documentation is quite brief and not many examples.
  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 02 Mar 2011 Link to this post

    Hello Xander,

    Sadly there is no FindString() or FindStringExact() methods in the CommandBarDropDown, but in the case you mentined you can just use c.SelectedText = "b";
    or you can always use linq to peform searches, maybe even an extension method, like so:
    public static class CommandBarDropDownExtensions
        public static RadListDataItem FindItem(this CommandBarDropDownList dropDown, string str)
            return dropDown.Items.Where(i => i.Text.Contains(str)).FirstOrDefault();

    and then use it like:
    c.SelectedItem = c.FindItem("b");
    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga
    Telerik WinForms MVP
  3. Peter
    Peter avatar
    1160 posts

    Posted 04 Mar 2011 Link to this post

    @Emanuel, thank you for your suggestion

    Hi Xander, actually there are FindItem and FindStringExact methods in CommandBarDropDown. However, you should access them using the DropDownListElement property. Consider the following sample:

    c.SelectedIndex = c.DropDownListElement.FindStringExact("a");

    I hope this helps. In case you have further questions, I will be glad to be of assistance.

    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  4. Xander
    Xander avatar
    12 posts
    Member since:
    Jan 2010

    Posted 10 Mar 2011 Link to this post

    Thanks, that's a lot easier.
Back to Top