Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6534369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:14:32+00:00 2026-05-25T10:14:32+00:00

I’ve been able to make 2 C# winform datagridviews drag and drop rows between

  • 0

I’ve been able to make 2 C# winform datagridviews drag and drop rows between them, but it uses a lot of code. Now I’m looking at creating a form that will contain 10 such grids, and I’m trying to reuse the code. I thought I could simply make a sub-class of DataGridView and add the event handlers, but I’m having trouble.

Specifically, how can I override the onDragDrop event, when the only event intellisense sees does not have the correct signature.

I see a signature like: protected override void OnDragDrop(DragEventArgs e), but I’m expecting a signature like protected override void OnDragDrop(object sender, DragEventArgs e), because I’m using sender in my code. What am I missing? How should I properly override this event? My non-working code is below:

public class DragGrid : DataGridView
{
    private DragGrid()
    {

    }

    private DragGrid(DataTable table)
    {
        this.DataSource = table;
    }

    protected override void OnDragEnter(DragEventArgs e)
    {
        base.OnDragEnter(e);
        e.Effect = DragDropEffects.Copy;
    }

    protected override void OnDragDrop(DragEventArgs e)
    {
        base.OnDragDrop(e);

        DataGridView grid = sender as DataGridView;
        DataTable table = grid.DataSource as DataTable;
        DataRow row = e.Data.GetData(typeof(DataRow)) as DataRow;

        if (row != null && table != null && row.Table != table)
        {
            table.ImportRow(row);
            row.Delete();
            table.AcceptChanges();
        }
    }

    protected override void OnMouseDown(MouseEventArgs e)
    {
        base.OnMouseDown(e);
        DragGrid.HitTestInfo info = ((DragGrid)this).HitTest(e.X, e.Y);

        if (info.RowIndex >= 0)
        {
            DataRow view = ((DataTable)(this.DataSource)).Rows[info.RowIndex];

            if (view != null)
            {
                this.DoDragDrop(view, DragDropEffects.Copy);
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:14:33+00:00Added an answer on May 25, 2026 at 10:14 am

    You are making mistake in definition between events and delegates:
    protected override void OnDragEnter(DragEventArgs e) { } is a method which invokes the event DragEnter of your datagrid.
    And when this event accurs, all the delegates with signature protected override void OnDragEnter(object sender, DragEventArgs e) { } are invoked.

    So you can’t override the event – this is just a field. You can override method which invokes it, but I think this is not that you are seeking for. I suggest you to add a handler for the DragEnter event for your script during your constructor:

    private DragGrid(DataTable table)
    {
        this.DataSource = table;
        this.DragEnter += new DragEventHandler(_onDragEnter);
    }
    private void _onDragEnter(object sender, DragEventArgs e)
    {
        // your code here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
I want to construct a data frame in an Rcpp function, but when I
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.