Back to Devexpress

GridViewBase.GridMenu Property

wpf-devexpress-dot-xpf-dot-grid-dot-gridviewbase-85537714.md

latest3.4 KB
Original Source

GridViewBase.GridMenu Property

Gets the context menu that is displayed within a View.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public GridPopupMenu GridMenu { get; }
vb
Public ReadOnly Property GridMenu As GridPopupMenu

Property Value

TypeDescription
GridPopupMenu

The context menu displayed within a View. null if no menu is displayed within a View.

|

Remarks

Refer to the Context Menus topic for more information.

Example

This example shows how to define a cell’s context menu. The context menu allows users to delete a row or copy its data to the clipboard.

View Example: Display a Context Menu for Data Cells

xaml
<dxg:GridControl.View>
    <dxg:TableView x:Name="view" AutoWidth="True">
        <dxg:TableView.RowCellMenuCustomizations>
            <dxb:BarButtonItem Name="deleteRowItem" Content="Delete"
                               IsEnabled="{Binding Row.Row.CanBeDeleted}"
                               ItemClick="OnDeleteRow"/>
            <dxb:BarButtonItem Name="copyCellDataItem" Content="Copy" 
                               ItemClick="OnCopyRow" />
        </dxg:TableView.RowCellMenuCustomizations>
    </dxg:TableView>
</dxg:GridControl.View>
cs
void OnCopyRow(object sender, ItemClickEventArgs e) {
    if (view.GridMenu.MenuInfo is GridCellMenuInfo menuInfo && menuInfo.Row != null)
        grid.CopyCurrentItemToClipboard();
}
void OnDeleteRow(object sender, ItemClickEventArgs e) {
    if (view.GridMenu.MenuInfo is GridCellMenuInfo menuInfo && menuInfo.Row != null)
        view.DeleteRow(menuInfo.Row.RowHandle.Value);
}
vb
Private Sub copyCellDataItem_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs)
    Dim menuInfo As GridCellMenuInfo = TryCast(view.GridMenu.MenuInfo, GridCellMenuInfo)
    If menuInfo IsNot Nothing AndAlso menuInfo.Row IsNot Nothing Then
        grid.CopyCurrentItemToClipboard()
    End If
End Sub

Private Sub deleteRowItem_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs)
    Dim menuInfo As GridCellMenuInfo = TryCast(view.GridMenu.MenuInfo, GridCellMenuInfo)
    If menuInfo IsNot Nothing AndAlso menuInfo.Row IsNot Nothing Then
        view.DeleteRow(menuInfo.Row.RowHandle.Value)
    End If
End Sub

See Also

Context Menus

GridViewBase Class

GridViewBase Members

DevExpress.Xpf.Grid Namespace