Drag and Drop into a DataGrid

K

Ken Loomis

Hello:

I have spent two days on drag and drop now and I'm getting no where.
I am trying to drag an item from a listbox and load it into a datagrid
(actually a child of the datagrid, but I'll be happy for now to get to
the parent.) I can get the selected row of the target, but that is
not the same as dropped_on row. I've tried to get the mouse_up
event, but drag and drop seems to override the mouse_up. I've tried
the hitTest but it seems also not to be activated in the drop event.

If I can get the row index, I think I can get the values I need.

Thanks,

Ken
 
B

Bart Mermuys

Hi,
[Inline]

Ken Loomis said:
Hello:

I have spent two days on drag and drop now and I'm getting no where.
I am trying to drag an item from a listbox and load it into a datagrid
(actually a child of the datagrid, but I'll be happy for now to get to
the parent.) I can get the selected row of the target, but that is
not the same as dropped_on row. I've tried to get the mouse_up
event, but drag and drop seems to override the mouse_up. I've tried
the hitTest but it seems also not to be activated in the drop event.

If I can get the row index, I think I can get the values I need.

It should work with HitTest, did you try something like:

private void dataGrid1_DragDrop(object sender,
System.Windows.Forms.DragEventArgs e)
{
DataGrid.HitTestInfo ht = dataGrid1.HitTest(
dataGrid1.PointToClient( new Point( e.X, e.Y ) ) );

Console.WriteLine( ht.Row );
Console.WriteLine( ht.Column );
Console.WriteLine( ht.Type );
}

HTH,
Greetings
 
K

Ken Loomis

It should work with HitTest, did you try something like:

private void dataGrid1_DragDrop(object sender,
System.Windows.Forms.DragEventArgs e)
{
DataGrid.HitTestInfo ht = dataGrid1.HitTest(
dataGrid1.PointToClient( new Point( e.X, e.Y ) ) );

Bart:
I had: dataGrid1.HitTest(e.X,e.Y).

I didn't know about PointToClient.

I guess the relevant information from the Help is:
"Because the DragEventArgs.X and DragEventArgs.Y values are screen
coordinates, the example uses the PointToClient method to convert them
to client coordinates."

Thanks very much.

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top