how to show visual feedback(red line) at drop location in datagrid instead of mouse curser.
Thanks in Advance
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Sandhiya PriyaRank #26 · 43.2K reputationPosted Jan 2, 2026, 6:21 AM EST
(WPF DataGrid):
To show visual feedback (a red line) at the drop location in a
DataGrid, you must draw an adorner during drag-over. WPF does not provide this automatically.The correct approach is to use a custom Adorner that draws a red line between rows.
How it works (concept)
Handle
DragOveron theDataGridDetect the row index under the mouse
Show a red horizontal line using an
AdornerRemove the adorner on
Drop/DragLeaveStep 1: Create a Row Drop Adorner
public class DataGridRowDropAdorner : Adorner { private readonly bool _isAbove; private readonly Pen _pen = new Pen(Brushes.Red, 2); public DataGridRowDropAdorner(DataGridRow row, bool isAbove) : base(row) { _isAbove = isAbove; IsHitTestVisible = false; } protected override void OnRender(DrawingContext dc) { var width = AdornedElement.RenderSize.Width; var y = _isAbove ? 0 : AdornedElement.RenderSize.Height; dc.DrawLine(_pen, new Point(0, y), new Point(width, y)); } }Step 2: Show the red line during DragOver
private AdornerLayer _adornerLayer; private Adorner _currentAdorner; private void DataGrid_DragOver(object sender, DragEventArgs e) { var row = GetRowUnderMouse(e); if (row == null) return; RemoveAdorner(); bool isAbove = e.GetPosition(row).Y < row.ActualHeight / 2; _adornerLayer = AdornerLayer.GetAdornerLayer(row); _currentAdorner = new DataGridRowDropAdorner(row, isAbove); _adornerLayer.Add(_currentAdorner); }Step 3: Remove the visual feedback
private void RemoveAdorner() { if (_adornerLayer != null && _currentAdorner != null) _adornerLayer.Remove(_currentAdorner); _currentAdorner = null; }Call
RemoveAdorner()on:DropDragLeaveStep 4: Helper to find the row
private DataGridRow GetRowUnderMouse(DragEventArgs e) { var element = e.OriginalSource as DependencyObject; return ItemsControl.ContainerFromElement(MyDataGrid, element) as DataGridRow; }Result
Red line appears between rows
Mouse cursor stays unchanged
Clear and professional drop indication
Summary
WPF doesn’t support row drop indicators by default
Use a custom Adorner
Draw a red line above/below the row
Remove it on drop
This is the standard and best-practice solution used in WPF applications.