Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 356
  • Last Modified:

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

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
dominicwong
Asked:
dominicwong
  • 2
1 Solution
 
AndyAinscowFreelance programmer / ConsultantCommented:
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
 
AndyAinscowFreelance programmer / ConsultantCommented:
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
 
dominicwongAuthor Commented:
Thanks Andy. It works.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now