Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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