RadMenuComboItem Events

3 posts, 0 answers
  1. Mike
    Mike avatar
    9 posts
    Member since:
    Apr 2009

    Posted 10 Jun 2009 Link to this post

    Good day!

    I've got two inter-related combos in the ribbonbar quick access menu, which will change the entity I'm looking at in my application, and I'd like the user to be able to select values in the following way:-

    a) By typing in the field, pressing enter
    b) By selecting an entry from the dropdown
    c) By using the arrow keys

    The problem I'm having is that I don't want to change the entity being looked at until either the user as pressed enter, or clicked on a specific item.

    I've met the first requirement by handling KeyPressed and looking for '\r', which works fine.  I can't find an appropriate item level handler. SelectedIndexChanged et al fire every time the user hits an arrow so that's no good. 

    I see you can manually assign a Click handler to each item in the radcombobox except that these two combos are databound, and have several hundred entries in each.  

    Because they're in the quick access menu, I can't think of any useful alternative options (e.g. having a "launch" button next to the combo for example, because when you select the item in the combobox, the menu disappears before you get a chance to click on anything else in the menu)

    Any thoughts would be appreciated, and I'm more than willing to consider different options here.
  2. Mike
    Mike avatar
    9 posts
    Member since:
    Apr 2009

    Posted 10 Jun 2009 Link to this post

    Screenshot

    Here's a screenshot of the opened menu
    Name and mnemonic are both quick access points that would take a user to the entity they want to look at.

    My "launch" button comment would be a hypothetical "launch" button appearing next to each combo to be clicked once the item in the combo is selected (as an alternative to my desired behaviour)


  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 11 Jun 2009 Link to this post

    Hi Mike,

    I am not quite sure what is the exact behavior that you want to achieve. However, you can fully customize the RadMenuComboItem behavior through inheriting. I am demonstrating this in the code snippet below:

    public class MyMenuComboItem : RadMenuComboItem 
        RadButtonElement buttonElement; 
     
        protected override void CreateChildElements() 
        { 
            base.CreateChildElements(); 
            this.ComboBoxElement.KeyDown += new KeyEventHandler(ComboBoxElement_KeyDown); 
            buttonElement = new RadButtonElement("..."); 
            buttonElement.Click += new EventHandler(button_Click); 
            this.ComboBoxElement.MinSize = new Size(0, 0); 
            this.Children.Add(buttonElement); 
        } 
     
        void ComboBoxElement_KeyDown(object sender, KeyEventArgs e) 
        { 
            if (e.KeyCode == Keys.Enter) 
            { 
                ((RadApplicationMenuButtonElement)this.Owner).HideDropDown(); 
            } 
        } 
     
        void button_Click(object sender, EventArgs e) 
        { 
            ((RadApplicationMenuButtonElement)this.Owner).HideDropDown(); 
        } 
     
        protected override SizeF MeasureOverride(SizeF availableSize) 
        { 
            SizeF desiredSize = SizeF.Empty; 
            foreach (RadElement element in this.Children) 
            { 
                element.Measure(availableSize); 
                desiredSize.Width += element.DesiredSize.Width; 
                desiredSize.Height = Math.Max(element.DesiredSize.Height, desiredSize.Height); 
            } 
            return desiredSize;             
        } 
     
        protected override SizeF ArrangeOverride(SizeF finalSize) 
        { 
            RectangleF clientRect = GetClientRectangle(finalSize); 
            foreach (RadElement element in this.Children) 
            { 
                if (this.ComboBoxElement == element) 
                { 
                    element.Arrange(new RectangleF(clientRect.X, (clientRect.Height - 20) / 2 + 2, 
                            clientRect.Width - this.buttonElement.DesiredSize.Width, 20)); 
                } 
                else if (this.buttonElement == element) 
                { 
                    element.Arrange(new RectangleF(clientRect.Right - this.buttonElement.DesiredSize.Width, clientRect.Y, 
                            clientRect.Height, this.Children[1].DesiredSize.Height)); 
                } 
                else 
                { 
                    element.Arrange(clientRect); 
                } 
            } 
             
            return finalSize; 
        } 

    Here, I handle the KeyDown event of the ComboBoxElement to process the Enter key and I am adding a RadButtonElement next to the combo box.

    If this is not exactly what you want, please give me a detailed description of the desired behavior and I will try to find a proper solution.

    I am looking forward to your reply.
     

    Kind regards,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top