GridControl.RowCellMenu Property
Gets or sets a context menu that is invoked when a user right-clicks a data cell, a row, or row indicator cells.
Namespace: DevExpress.WinUI.Grid
Assembly: DevExpress.WinUI.Grid.v23.2.dll
NuGet Package: DevExpress.WinUI
#Declaration
#Property Value
Type | Description |
---|---|
Object | A UI element invoked when a user right-clicks a data cell, a row, or row indicator cells. |
#Remarks
The RowCellMenu property allows you to define a custom context menu for rows and cells. To do this, assign a MenuFlyout control to this property.
When you assign a menu control to the RowCellMenu, this control’s DataContext is set to an object of the GridRowCellContextMenuInfo type. This class contains information about the GridControl, the view model stored in its DataContext, the target cell, and so on.
The following code sample demonstrates how to specify a context menu for rows and cells:
<dxg:GridControl ItemsSource="{x:Bind ViewModel.Source}"
ShowRowIndicator="True">
<dxg:GridControl.RowCellMenu>
<MenuFlyout>
<MenuFlyoutItem Text="Delete"
Command="{x:Bind ViewModel.DeleteRowCommand}"
CommandParameter="{Binding Cell.CellData.Row}"/>
<MenuFlyoutItem Text="Duplicate"
Command="{x:Bind ViewModel.DuplicateRowCommand}"
CommandParameter="{Binding Cell.CellData.Row}"/>
</MenuFlyout>
</dxg:GridControl.RowCellMenu>
</dxg:GridControl>
public class MainViewModel : ViewModelBase {
public MainViewModel() {
// ...
DeleteRowCommand = new DelegateCommand<Product>(DeleteRow);
DuplicateRowCommand = new DelegateCommand<Product>(DuplicateRow);
}
// ...
public DelegateCommand<Product> DeleteRowCommand { get; private set; }
public DelegateCommand<Product> DuplicateRowCommand { get; private set; }
public void DeleteRow(Product product) {
Source.Remove(product);
}
public void DuplicateRow(Product product) {
var index = Source.IndexOf(product);
Source.Insert(index, product);
}
}