473,225 Members | 1,513 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 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 9130
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Spencer Williamson | last post by:
Anyone know how to force the row to select when user right clicks the grid? I have SelectionMode set to DataGridViewSelectionMode.FullRowSelect. I tried this... Private Sub...
0
by: Code Monkey | last post by:
In project there is a DataGridView. I have a little bit of code that I which displays information based on the cell that was clicked. My problem is how to detect if the user clicked on a...
0
by: Simmy | last post by:
I posted this on the MSDN forums and haven't gotten any response. Is there a way to determine a Datagridview column x coordinate? I don't mean when a user clicks and the hittest method is used to...
2
by: steve | last post by:
Hi All How do I get the screen coordinates of the selected cell boundaries in a datagridview I need to position a form at the top left position of the selected cell regardless of where the...
0
by: =?Utf-8?B?UHVjY2E=?= | last post by:
-- Hi, I'm using vs2005,. .net 2.0 for windows applicaiton. I'm doing drag and drop of 1 row of data at a time between 2 datagridview controls. I'm using the myDataGridView.DragDrop event to get...
4
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, I've a MouseEnter event on a dataGrid, and I want to know, if the mouse entered column no. 0 or column no. 1 . How can it be done? Thanks, Gidi.
1
by: szuccaro | last post by:
I am reading an excel file into a datagridview and trying to perform some function based on the column header that is clicked. I currently can produce an event to occur (msgbox) but, I need to get...
3
by: hzgt9b | last post by:
Using VS2005, VB.NET, I am developing a windows app that has a DataGridView. I want to enable the display of a context menu on this DataGridView only when a specific set of keys is also pressed...
1
by: Alex | last post by:
Hi, I need an event to fire off when someone clicks anyplace within a DataGridView row, but whether I use CellContentClick or CellClick, the event only fires off when clicking on the text within...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.