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
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!
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
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 >>
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
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 >>
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
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,
Jackthe 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 >>