How to change mouse cursor for selection and dragging in WPF GridControl?
WPF GridControl provide supports for range and record selection modes and drag and drop functionality. You can drag and drop the values from range of cells within a grid or multiple grids enable by setting the AllowDragDrop property as true. In this article, you will see how to change the mouse cursor style for selected cells and while dragging the selected cells.
Change the mouse cursor for selected cells
When you want to change the mouse cursor for set of selected cells or specific cell or rows or columns, you can use the MouseMove event and need to use the Cursor property. Refer the below code for your reference.
gridControl.MouseMove += Grid_MouseMove; private void Grid_MouseMove(object sender, MouseEventArgs e) { var _grid = sender as GridControl; RowColumnIndex rowColumn = _grid.PointToCellRowColumnIndex(e); if (_grid.Model.SelectedRanges.AnyRangeContains(GridRangeInfo.Cell(rowColumn.RowIndex, rowColumn.ColumnIndex))) { _grid.Cursor = Cursors.Hand; } else _grid.Cursor = Cursors.Arrow; }
Change the mouse cursor for while dragging the selected cells
When you want to change the mouse cursor when dragging a set of selected cells or specific cell or rows or columns, you can use the GiveFeedback event and need to use the Cursor property of the grid control.
Refer the below code for your reference.
gridControl.GiveFeedback += GridControl_GiveFeedback; private void GridControl_GiveFeedback(object sender, GiveFeedbackEventArgs e) { if (e.Effects == DragDropEffects.Copy || e.Effects == DragDropEffects.Move) { e.UseDefaultCursors = false; //To change the cursor while dragging. grid.Cursor = Cursors.SizeAll; e.Handled = true; } }
Sample: View sample in GitHub