In XAF applications, List Views can have context menus filled with Actions. For this purpose, the List Editor displaying a List View should support the IRequireContextMenu and IRequireDXMenuManager interfaces. This topic describes how to implement these interfaces in the WinCustomListEditor demonstrated in the How to: Implement a Custom WinForms List Editor topic.
The following image illustrates the context menu invoked for the WinCustomListEditor.
NoteYou can see the code implemented here in the FeatureCenter demo installed with XAF. This demo is located in the %PUBLIC%\Documents\DevExpress Demos 17.2\Components\eXpressApp Framework\FeatureCenter folder by default.
To enable the context menu in a custom List Editor, modify its code in the following manner.
C# |
[ListEditor(typeof(IPictureItem))]
public class WinCustomListEditor : ListEditor, IRequireContextMenu, IRequireDXMenuManager {
#region IRequireContextMenu Members
private void BarManager_QueryShowPopupMenu(object sender, QueryShowPopupMenuEventArgs e) {
if (e.Control != control) {
e.Cancel = true;
e.BreakShowPopupMenu = false;
}
}
public void SetMenu(PopupMenu popupMenu, BarManager barManager) {
barManager.SetPopupContextMenu(control, popupMenu);
barManager.QueryShowPopupMenu += BarManager_QueryShowPopupMenu;
}
#endregion
#region IRequireDXMenuManager Members
public void SetMenuManager(IDXMenuManager menuManager) { }
#endregion
}
|
VB |
<ListEditor(GetType(IPictureItem))> _
Public Class WinCustomListEditor
Inherits ListEditor
Implements IRequireContextMenu, IRequireDXMenuManager
#Region "IRequireContextMenu Members"
Private Sub BarManager_QueryShowPopupMenu(ByVal sender As Object, ByVal e As QueryShowPopupMenuEventArgs)
If e.Control <> control Then
e.Cancel = True
e.BreakShowPopupMenu = False
End If
End Sub
Public Sub SetMenu(ByVal popupMenu As PopupMenu, ByVal barManager As BarManager)
barManager.SetPopupContextMenu(control, popupMenu)
AddHandler barManager.QueryShowPopupMenu, AddressOf BarManager_QueryShowPopupMenu
End Sub
#EndRegion
#Region "IRequireDXMenuManager Members"
Public Sub SetMenuManager(ByVal menuManager As IDXMenuManager)
End Sub
#EndRegion
End Class
|
If you implement a List Editor using a descendant of the EditorContainer control, initialize the EditorContainer.MenuManager property in the SetMenuManager method.
In the QueryShowPopupMenu event handler, you can specify whether or not to cancel showing the context menu for the current region of the control using the e.Cancel parameter. For instance, you can use the following logic for the GridView control.
C# |
GridHitTest hitTest = gridView.CalcHitInfo(gridControl.PointToClient(e.Position)).HitTest;
e.Cancel = !(((hitTest == GridHitTest.Row) ||
(hitTest == GridHitTest.RowCell) || (hitTest == GridHitTest.EmptyRow) ||
(hitTest == GridHitTest.RowDetail) || (hitTest == GridHitTest.None)));
|
VB |
Dim hitTest As GridHitTest = gridView.CalcHitInfo(gridControl.PointToClient(e.Position)).HitTest
e.Cancel = Not(((hitTest Is GridHitTest.Row) OrElse _
(hitTest Is GridHitTest.RowCell) OrElse (hitTest Is GridHitTest.EmptyRow) OrElse _
(hitTest Is GridHitTest.RowDetail) OrElse (hitTest Is GridHitTest.None)))
|