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

CommandBarDropDownList SelectedIndexChanged Event

3 Answers 144 Views
CommandBar
This is a migrated thread and some comments may be shown as answers.
Marco
Top achievements
Rank 1
Marco asked on 12 Mar 2012, 11:43 AM
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

3 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 14 Mar 2012, 12:38 PM
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 >>
0
Marco
Top achievements
Rank 1
answered on 14 Mar 2012, 03:39 PM
Hello Stefan,

thank you that helps me...

Regards
Marco

0
Stefan
Telerik team
answered on 19 Mar 2012, 10:06 AM
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 >>
Tags
CommandBar
Asked by
Marco
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Marco
Top achievements
Rank 1
Share this question
or