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

Drop Down Button Databinding. Or dynamically adding and removing items.

7 Answers 510 Views
Buttons, RadioButton, CheckBox, etc
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 25 Jul 2011, 09:13 PM
Hi,

First let me stay, these are the best controls we have used! Our company has been using your controls for about 4 months now, telerik > devexpress.

So, We are working on a very simple winform. We have added a RadDropDownButton to this form. We want to bind this drop down like you would a combobox, but I have noticed there is no DataSource method for this. How would we dynamically add and remove items from this list at runtime from a SQL database?

Sorry if this is a duplicate question, i did search at no avail.

We have the latest version of the controls, .net 4.0, C#, VS2010,WIN7 x64. 


Thank you!

7 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 28 Jul 2011, 12:42 PM
Hi Matt,

Thank you for this question.

RadDropDownButton is not a data bound control and because of this it does not contain a DataSource property. You have to add/remove items manually by accessing its Items collection. Only data bound controls like RadGridView, RadTreeView or RadListControl expose a DataSource property in WinForms. 

All the best,
Jack
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Matt
Top achievements
Rank 1
answered on 24 Aug 2011, 05:21 PM
Jack,

Thank you for the reply. 

I have ended up adding items dynamically using the following.

string[] filePaths = Directory.GetFiles(@"C:\Templates\", "*.docx");
 
foreach (string s in filePaths)
{
      _docGenDropDownButton.Items.Add(new RadMenuItem(s.ToString()));                 
}

how could I then handle the click event for each item?

Thank you for your time.

-Matt
0
Jack
Telerik team
answered on 29 Aug 2011, 12:28 PM
Hi Matt,

You should handle the Click event for RadMenuItem. I modified your code snippet to demonstrate this:
string[] filePaths = Directory.GetFiles(@"C:\Templates\", "*.docx");
 
foreach (string s in filePaths)
{
    RadMenuItem menu = new RadMenuItem(s.ToString());
    menu.Click += new EventHandler(menu_Click);
    _docGenDropDownButton.Items.Add();
}
 
void menu_Click(object sender, EventArgs e)
{
             
}

Best wishes,
Jack
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Matt
Top achievements
Rank 1
answered on 07 Sep 2011, 08:59 PM
Thank you again for your answer.

That works perfectly!

However, how do I know which item i have clicked?

I'm sure I need to cast the EventArgs as something?

Thanx for the great customer support!

-Matt
0
Jack
Telerik team
answered on 08 Sep 2011, 04:11 PM
Hi Matt,

The sender argument of the event contains the RadMenuItem. Consider the following example:

void item_Click(object sender, EventArgs e)
{
    RadMenuItem item = (RadMenuItem)sender;
    //...
}

Greetings,
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Matt
Top achievements
Rank 1
answered on 08 Sep 2011, 04:40 PM
Thank you for the reply.

I have done this already, I guess I should have better asked the question.

How do I get the text from the item clicked? I did a quick watch on "item" and cannot find it :/



-Matt
0
Jack
Telerik team
answered on 13 Sep 2011, 12:08 PM
Hi Matt,

I am not sure whether I understand the issue correctly. You can use the Text property of RadMenuItem in order to access the item text. Here is a sample:
void item_Click(object sender, EventArgs e)
{
    RadMenuItem item = (RadMenuItem)sender;
    string text = item.Text;
    //...
}

Regards,

Jack
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
Buttons, RadioButton, CheckBox, etc
Asked by
Matt
Top achievements
Rank 1
Answers by
Jack
Telerik team
Matt
Top achievements
Rank 1
Share this question
or