I want to drag an ui element from another part of the screen to only the selected row of a gridview. The workflow is that use selects one row on the gridview (row multiselection is disabled) and then drags something on that row.
So only if the mouse cursor is on top of the selected row the cursor should change to DragDropEffects.Link. Any other row, column header, filter header, grouping are etc. should show DragDropEffects.None. I also want to change the row border od the selected row ro green color if possible to indicate that this drop is allowed.
Then I have some business logic to with the AddressBase object in the gridviewinfo.tag of the selected row and the data in the DragEventArgs. So far I have managed to do this in the grid's DragOver event handler. But how do I check that the element at mouse location is within the border of the selected row.
private void PersonMailingGridOnDragOver(object sender, DragEventArgs e)
{
Point location = PersonMailingGrid.PointToClient(new Point(e.X, e.Y));
GridDataCellElement element = PersonMailingGrid.ElementTree.GetElementAtPoint(location) as GridDataCellElement;
// check that the element is inside the selected row
if (element != null && !(element is GridFilterCheckBoxCellElement))
{
AddressEventArgs data = (AddressEventArgs)e.Data.GetData(typeof(AddressEventArgs));
AddressBase dragAddress = data.Address;
AddressBase rowAddress = element.GridViewElement.CurrentRow.Tag as AddressBase;
_lastDragElement = element.GridViewElement;
_lastDragElementBackColor = element.RowElement.BackColor;
if (rowAddress != null && rowAddress.AddressContactType == dragAddress.AddressContactType)
{
e.Effect = DragDropEffects.Link;
element.RowElement.BackColor = _dragStateBorderColourAllowed;
}
else
{
e.Effect = DragDropEffects.None;
element.RowElement.BackColor = _dragStateBorderColourNotAllowed;
}
}
}