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

8 posts, 0 answers
  1. Matt
    Matt avatar
    5 posts
    Member since:
    Mar 2011

    Posted 25 Jul 2011 Link to this post

    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!
  2. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 28 Jul 2011 Link to this post

    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!

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Matt
    Matt avatar
    5 posts
    Member since:
    Mar 2011

    Posted 24 Aug 2011 Link to this post

    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
  5. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 29 Aug 2011 Link to this post

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

  6. Matt
    Matt avatar
    5 posts
    Member since:
    Mar 2011

    Posted 07 Sep 2011 Link to this post

    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
  7. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 08 Sep 2011 Link to this post

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

  8. Matt
    Matt avatar
    5 posts
    Member since:
    Mar 2011

    Posted 08 Sep 2011 Link to this post

    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
  9. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 13 Sep 2011 Link to this post

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

Back to Top
UI for WinForms is Visual Studio 2017 Ready