I have a Windows Forms application where I need to be able to drag and
then drop onto a datagridview control. I already have the code
necessary to make the drag part work. I am having problems, however,
when I attempt to drop onto a cell in the datagridview. So far
I have done the following with the datagridview control...
1. I set "AllowDrop" to true.
2. In the DragEnter event I put this...
if (e.Data.GetDataPresent(DataFormats.Text)) { e.Effect =
DragDropEffects.Copy; }
else { e.Effect = DragDropEffects.None; }
3. In the DragDrop event I put this...
this.dgvMyGrid.CurrentCell.Value =
e.Data.GetData(DataFormats.Text).ToString();
The code already works...well sort of. When I drag and drop, the mouse
changes to show there is data, and then it gets put into the selected
cell when I drop. BUT, I can't have the user to manually "select" the
cell prior to each drag and drop operation. That doesn't make sense.
You see, I need for the drop to occur in whatever cell I release over,
instead of whatever cell was already selected. In effect, the cell
should "auto select" whenever the drop occurs on it.
How do I do that?