Solved Drag and drop from one cell on a DataGridView  to another

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

What 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:murbro
    LVL 40

    Expert Comment

    by:Jacques Bourgeois (James Burger)
    What is the logic of dragging without transferring a value? This would be counter-intuitive for the user.

    Author Comment

    The logic is to highlight the cells as a pair
    LVL 40

    Accepted Solution

    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

    Thanks very much

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    733 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now