Solved

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

Posted on 2013-06-25
3
342 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 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