Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
660
UltraDropDownButton: Problems showing a simple ContextMenuStrip
posted

I need a simple solution to have a Button next to an edit field to show up some simple options for the user to choose from.

I thought and tried this:
- put an UltraDropDownButton on the Form
- put an UltraPopupControlContainer on the Form
- put an ContextMenuStrip on the Form

I choosed a simple MenuStrip because it's simple to use (i only need a few entries that i put in at runtime)

In the PopupContainer i've set "PopupControl" to the MenuStrip (design time)

In the DropDownButton i've set "PopupItem" to the "MenuStrip [PopupControlContainer]" (design time)

 

Now, if i run the application and press the DropDownButton i get an error: (translated something like 'the control of the topmost level cannot added to a control')

System.ArgumentException wurde nicht behandelt.
  Message="Das Steuerelement der obersten Ebene kann nicht zu einem Steuerelement hinzugefügt werden."
  Source="System.Windows.Forms"
  StackTrace:
       bei System.Windows.Forms.Control.ControlCollection.Add(Control value)
       bei System.Windows.Forms.Form.ControlCollection.Add(Control value)
       bei System.Windows.Forms.Control.set_ParentInternal(Control value)
       bei System.Windows.Forms.Control.set_Parent(Control value)
       bei Infragistics.Win.DropDownManager.ShowDropDown()
       bei Infragistics.Win.DropDownManager.DropDown(DropDownManagerParameters dropDownManagerParameters)
       bei Infragistics.Win.DropDownManager.DropDown(Control owner, Control dropdownControl, Control editControl, EventHandler closeUpHandler, Rectangle exclusionArea, Size dropDownSize, Point location, Boolean alignRight, Boolean clearExisting, Boolean autoCloseUp, Boolean ignoreClicksInExclusionArea, DropDownPosition dropDownPosition, Boolean eatMouseMessageOnAutoCloseup)
       bei Infragistics.Win.Misc.UltraPopupControlContainer.Show(PopupInfo info)
       bei Infragistics.Win.Misc.UltraDropDownButton.DropDown()
       bei Infragistics.Win.Misc.SplitButtonUIElement.OnMouseDown(MouseEventArgs e, Boolean adjustableArea, UIElement& captureMouseForElement)
       bei Infragistics.Win.ControlUIElementBase.ProcessMouseDownHelper(Object sender, MouseEventArgs e)
       bei Infragistics.Win.ControlUIElementBase.ProcessMouseDown(Object sender, MouseEventArgs e)
       bei Infragistics.Win.Utilities.ProcessEvent(Control control, ProcessEvent eventToProcess, EventArgs e)
       bei Infragistics.Win.UltraControlBase.OnMouseDown(MouseEventArgs e)
       bei System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
       bei System.Windows.Forms.Control.WndProc(Message& m)
       bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       bei System.Windows.Forms.Application.RunDialog(Form form)
       bei System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
       bei mycompany.Material.ds4.UArtikelPreis.pbDetails_Click(Object sender, EventArgs e) in V:\VS\bs Beta\mycompany\Material\ds4\EmbeddedForms\UArtikelPreis.cs:Zeile 174.
       bei System.Windows.Forms.Control.OnClick(EventArgs e)
       bei Infragistics.Win.UltraControlBase.OnClick(EventArgs e)
       bei Infragistics.Win.Misc.UltraButtonBase.OnClick(EventArgs e)
       bei Infragistics.Win.Misc.UltraButton.OnMouseUp(MouseEventArgs e)
       bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       bei System.Windows.Forms.Control.WndProc(Message& m)
       bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       bei System.Windows.Forms.Application.Run(Form mainForm)
       bei mycompany.Material.ds4.Program.Main() in V:\VS\bs Beta\mycompany\Material\ds4\Classes\Program.cs:Zeile 18.
       bei System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       bei System.Threading.ThreadHelper.ThreadStart()
  InnerException:

 

In this case i have:
- a windows form
- on that form a UserControl i've written
- That UserControl is creating other UserControls at runtime and placing it on itself
- These runtime-created UserControls are the ones that have the DropDownButton on it (besides other controls) plus the MenuStrip and the PopupControlContainer of course.

If you have any idea how to solve this please let me know. If you have another simple idea how to get a small dropdown-button showing a simple menu i would be happy too. I decided to choose Infragistic DropDownButton in case that some day i need to popUp a more complex UserControl or something else instead of that simple menu - so it would be easier to extend in future... But if this is too complex i would rather choose a simpler way :)

Parents
No Data
Reply
  • 469350
    Suggested Answer
    Offline posted

    Hi,

    PopupControlContainer needs to contain a fixed Control. The ContextMenu really isn't a control - it's another popup. So that's not going to do what you want.

    The PopupItem on the UltraDropDownButton takes an IPopupItem. There are two things that implement this interface. The first is the PopupControlContainer - but as we've already established, that won't work for you.

    The second is a PopupMenu from an UltraToolbarsManager. So what you could so here is use an UltraToolbarsManager and go into the designer and create a PopupMenu with some items on it, rather than using the inbox ContextMenu(Strip).

    Another option would be to use UltraTextEditor ar eyou "edit field", or maybe one of the other editor controls. You could use the ButtonsRight collection to add a button to the control. Then you could trap for a MouseUp event on the control, use the UIElements to determine the location of the MouseUp and determine if it was on the button. And then you could manually show your ContextMenu.

Children
No Data