Solved

How to distinguish drag-and-drop at the top and at the bottom in Datagridview in Winform

Posted on 2013-06-25
3
339 Views
Last Modified: 2013-06-25
Hi experts
I've, for example, a datagridview with 3 rows (only 1 single column).

When I drag-and-drop an item to under the bottom row, the hit-test row index returned was "-1".
When I drag-and-drop an item to above the first row (ie at the row header), the hit-test row index returned was also "-1".

My question is: how to distinguish the two situations. Thanks in advance.

 Point clientPoint = _dgv2.PointToClient(new Point(e.X, e.Y));
 int dropPosition = _dgv2.HitTest(clientPoint.X, clientPoint.Y).RowIndex;

Open in new window

0
Comment
Question by:dominicwong
  • 2
3 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 39273975
There may be a better way but if you check the y co-ordinate and compare that to the y co-ordinate of the grid on screen you should be able to tell if it is near the top of the grid ( = before the first row) or rather lower down ( = after the last row)
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39273979
ps.  The -1 indicates it is not over an existing row, I think you then have to use some indirect method to determine further.
0
 

Author Closing Comment

by:dominicwong
ID: 39276649
Thanks Andy. It works.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question