Solved

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

Posted on 2013-06-25
3
346 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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:…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

617 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