473,497 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 9191
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
18052
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
1418
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
1189
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
19106
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
1446
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
3806
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
10516
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
5225
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
9545
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
7120
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6991
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6878
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7373
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4583
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
286
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.