Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Buttons, RadioButton, CheckBox, etc > Drop Down Button Databinding. Or dynamically adding and removing items.

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

Feed from this thread
  • Matt avatar

    Posted on Jul 25, 2011 (permalink)

    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!

    Reply

  • Jack Jack admin's avatar

    Posted on Jul 28, 2011 (permalink)

    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!

    Reply

  • Matt avatar

    Posted on Aug 24, 2011 (permalink)

    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

    Reply

  • Jack Jack admin's avatar

    Posted on Aug 29, 2011 (permalink)

    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 >>

    Reply

  • Matt avatar

    Posted on Sep 7, 2011 (permalink)

    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

    Reply

  • Jack Jack admin's avatar

    Posted on Sep 8, 2011 (permalink)

    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 >>

    Reply

  • Matt avatar

    Posted on Sep 8, 2011 (permalink)

    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

    Reply

  • Jack Jack admin's avatar

    Posted on Sep 13, 2011 (permalink)

    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 >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Buttons, RadioButton, CheckBox, etc > Drop Down Button Databinding. Or dynamically adding and removing items.
Related resources for "Drop Down Button Databinding. Or dynamically adding and removing items."

[ Features | Demos | Documentation | Knowledge Base | Telerik TV | Code Library | Step-by-step Tutorial | Blogs | Self-Paced Trainer ]