Displaying the XtraScheduler Context Menu Programmatically

The XtraScheduler product from DevExpress is suite of flexible and powerful calendar controls. The scheduler control itself has a built in popup menu that displays context sensitive items when the end-user right-clicks the control.

However, it’s not immediately obvious how to display this menu, with the appropriate context options, programmatically. For instance, you may have an XtraGrid control setup synchronized with the XtraScheduler control. It would be pretty sweet if right-clicking an appointment in the XtraGrid control displayed the appropriate XtraScheduler context menu.

With some digging through the XtraScheduler classes, comments, and some trial and error, I was able to come up with the following working code:

        private void gridControl1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                SchedulerHitInfo hitInfo = new SchedulerHitInfo(SelectableIntervalViewInfo.Empty, SchedulerHitTest.AppointmentContent);
                WinFormsSchedulerMenuBuilderUIFactory uiFactory = new WinFormsSchedulerMenuBuilderUIFactory();
                SchedulerDefaultPopupMenuWinBuilder builder = new SchedulerDefaultPopupMenuWinBuilder(uiFactory, schedulerControl, hitInfo);
                IDXPopupMenu<SchedulerMenuItemId> popupMenu = builder.CreatePopupMenu();
                ((IDXDropDownControl)popupMenu).Show(schedulerControl.MenuManager, (Control)sender, new System.Drawing.Point(e.X, e.Y));
            }
        }

The first line creates a new instance SchedulerHitInfo with SchedulerHitTest.AppointmentContent specified as the element under the hit info. This controls which menu contents will be displayed. In this case, the menu contents shown when right-clicking an appointment are displayed.

The next three lines create the popup menu itself by using a WinFormsSchedulerMenuBuilderUIFactory and WinFormsSchedulerMenuBuilderUIFactory.

Finally, the last line displays the popup menu itself. The first parameter is an IDXMenuManager, which can be accessed via the MenuManager property of the scheduler control. The second parameter is the parent control for the popup menu. The final parameter is the position for the popup menu within the parent control.

Together, these lines allow you to display the XtraScheduler menu, with the appropriate context sensitive contents and at any position, from code. Hopefully this bit of code comes in handy as these classes aren’t currently (well) documented. Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>