This is a migrated thread and some comments may be shown as answers.

Allowing Drag and Drop only on top of selected row

1 Answer 79 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pratik
Top achievements
Rank 1
Pratik asked on 05 Oct 2012, 12:43 AM

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;
  }
 }
}

 

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Svett
Telerik team
answered on 08 Oct 2012, 02:42 PM
Hi Pratik,

You can determine whether the hovered cell is owned by the current row by accessing its RowInfo property. You can use the following code snippet:
GridDataCellElement element = PersonMailingGrid.ElementTree.GetElementAtPoint(location) as GridDataCellElement;
 
if (element.RowInfo.IsCurrent)
{
}

I hope this helps.

Kind regards,
Svett
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Pratik
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or