471,317 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 software developers and data experts.

Invalid coordinates from dataGridView HitTest

I am trying to implement a drag and drop operation from a listbox to a data
gridview control but I keep getting -1 for my row index when the dragdrop
function is executed. Below is my coding.

DataGridView.HitTestInfo info = dataGridView2.HitTest(e.X, e.Y);
int row = info.RowIndex;

The coordinates returned to the dragdrop function seem to be coordinates
relative to the window rather than to the datagridview control. In any case,
I get -1 for of the indices returned in the info group. Does anyone know how
to get the correct row in a dragdrop into a datagridview.
Dave
Aug 3 '08 #1
2 8738
Parrot ha scritto:
I am trying to implement a drag and drop operation from a listbox to a data
gridview control but I keep getting -1 for my row index when the dragdrop
function is executed. Below is my coding.

DataGridView.HitTestInfo info = dataGridView2.HitTest(e.X, e.Y);
int row = info.RowIndex;

The coordinates returned to the dragdrop function seem to be coordinates
relative to the window rather than to the datagridview control. In any case,
I get -1 for of the indices returned in the info group. Does anyone know how
to get the correct row in a dragdrop into a datagridview.
Dave
Hi Parrot,
you have to use
Control.PointToClient(pt)

Bests,
Stefano
Aug 3 '08 #2
Stefano:
Thanks for your reply. I inserted the following command before the HitTest
as shown below and the row index was correct.

Point p = dataGridView2.PointToClient(new Point(e.X, e.Y);
DataGridView.HitTestInfo info = dataGridView2.HitTest(p.X, p.Y);
int row = info.RowIndex;

Thanks for your help.
"Stefano Tonello" wrote:
Parrot ha scritto:
I am trying to implement a drag and drop operation from a listbox to a data
gridview control but I keep getting -1 for my row index when the dragdrop
function is executed. Below is my coding.

DataGridView.HitTestInfo info = dataGridView2.HitTest(e.X, e.Y);
int row = info.RowIndex;

The coordinates returned to the dragdrop function seem to be coordinates
relative to the window rather than to the datagridview control. In any case,
I get -1 for of the indices returned in the info group. Does anyone know how
to get the correct row in a dragdrop into a datagridview.
Dave

Hi Parrot,
you have to use
Control.PointToClient(pt)

Bests,
Stefano
Aug 3 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Spencer Williamson | last post: by
reply views Thread by Code Monkey | last post: by
reply views Thread by =?Utf-8?B?UHVjY2E=?= | last post: by
4 posts views Thread by =?Utf-8?B?R2lkaQ==?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.