CommandBarDropDownList SelectedIndexChanged Event

4 posts, 1 answers
  1. Marco
    Marco avatar
    19 posts
    Member since:
    Oct 2011

    Posted 12 Mar 2012 Link to this post

    Hi,

    I use the CommandBar with two CommandBarDropDownList items and I attach the SelectedIndexChanged event.
    In the event handler I want to cast the sender object to the CommandBarDropDownList, but this doesn't work, because the sender is a type of RadDropDownListElement.
    I need the Tag property from the CommandBarDropDownList item, because I use it in my following code.
    If I cast the sender object to the RadDropDownListElement, the Tag property is null!

    Is this a bug?

    Regards
    Marco

  2. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 14 Mar 2012 Link to this post

    Hello Marco,

    Thank you for writing.

    Indeed, the sender in the event mentioned is RadDropDownListElement. In order to get the CommandBarDropDownList, you should access the Parent of the RadDropDownListElement. Here is a sample:
    public Form1()
    {
        InitializeComponent();
     
        commandBarDropDownList1.Tag = "First DropDownList";
        commandBarDropDownList2.Tag = "Second DropDownList";
     
        commandBarDropDownList1.SelectedIndexChanged += new Telerik.WinControls.UI.Data.PositionChangedEventHandler(commandBarDropDownList1_SelectedIndexChanged);
        commandBarDropDownList2.SelectedIndexChanged += new Telerik.WinControls.UI.Data.PositionChangedEventHandler(commandBarDropDownList1_SelectedIndexChanged);
    }
     
    void commandBarDropDownList1_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
    {
        RadDropDownListElement el = sender as RadDropDownListElement;
        CommandBarDropDownList ddl = el.Parent as CommandBarDropDownList;
        RadMessageBox.Show(ddl.Tag.ToString());
    }

    I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.
     
    Regards,
    Stefan
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Marco
    Marco avatar
    19 posts
    Member since:
    Oct 2011

    Posted 14 Mar 2012 Link to this post

    Hello Stefan,

    thank you that helps me...

    Regards
    Marco

  5. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 19 Mar 2012 Link to this post

    Hello Marco,

    I am glad that I could help. Let us know if you have any other questions.
     
    Greetings,
    Stefan
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top