VB.net Drag and drop from one cell on a DataGridView  to another

Posted on 2014-08-16
Medium Priority
Last Modified: 2014-08-16

What VB.net code would I use to drag from one DataGridView cell to another leaving both cells color as yellow and not dragging any values?
Question by:Murray Brown
  • 2
  • 2
LVL 40
ID: 40265082
What is the logic of dragging without transferring a value? This would be counter-intuitive for the user.

Author Comment

by:Murray Brown
ID: 40265127
The logic is to highlight the cells as a pair
LVL 40

Accepted Solution

Jacques Bourgeois (James Burger) earned 2000 total points
ID: 40265145
Personally, I feel that something like that would be better done another way.

When the user drags, he expects a transfer, either a copy or a move.

When he needs to select many elements together, the standard is Ctrl-Click.

Unless you use Ctrl-Click for something else in the grid, I would go that route. Not only will it be easier to code, but it will be more natural for the user. On the first Ctrl-Click, you set the first cell to yellow, and on the second Ctrl-Click, you set the second cell.

You can trap a Ctrl-Click with code like the following:

	Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
		If Control.ModifierKeys = Keys.Control Then
			'Do what you need
		End If
	End Sub

Open in new window

If you expect to make more than one such pairs, you should think of using different colors for each pair.

Author Closing Comment

by:Murray Brown
ID: 40265146
Thanks very much

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

840 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