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 8114459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:09:09+00:00 2026-06-06T03:09:09+00:00

I want to drop some data from treeview to the datagridview temporarily, but the

  • 0

I want to drop some data from treeview to the datagridview temporarily, but the datagrid view is already loaded some data from a xml file.

Someone Please explain to me the mechanism of this.

This is my drag/drop function: //It works perfectly if there is no data in the datagrid view.

  private void DataGridView1OnDragDrop(object sender, DragEventArgs e)
    {
        Point dscreen = new Point(e.X, e.Y);
        Point dclient = dataGridView1.PointToClient(dscreen);
        DataGridView.HitTestInfo hitTest = dataGridView1.HitTest(dclient.X, dclient.Y);

        if (hitTest.ColumnIndex == 0 && hitTest.Type == DataGridViewHitTestType.Cell)
        {
            e.Effect = DragDropEffects.Move;
            //dataGridView1.Rows.Insert(hitTest.RowIndex, "hitTest", "hitTest", "hitTest", "hitTest");
            var data = (object[]) e.Data.GetData(typeof(string[]));
            dataGridView1.Rows.Insert(hitTest.RowIndex, data);

        }
        else
        {
            e.Effect = DragDropEffects.None;
        }
        dataGridView1.AllowUserToAddRows = false;
    }

For datagrid:

XmlReader xmlFile;
xmlFile = XmlReader.Create("Product.xml", new XmlReaderSettings());
DataSet ds = new DataSet();
ds.ReadXml(xmlFile);
dataGridView1.DataSource = ds.Tables[0];

For Treeview:

var filename = @"C:\Check.xml";
//First, we'll load the Xml document
XmlDocument xDoc = new XmlDocument();
xDoc.Load(filename);
  • 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-06-06T03:09:10+00:00Added an answer on June 6, 2026 at 3:09 am

    Instead of adding the drag-drop-data to the control you should add it to the datasource of the control.

    // will allow you to drop your data anywhere on gridview where a cell is
    if (hitTest.Type == DataGridViewHitTestType.Cell)
    {
       e.Effect = DragDropEffects.Move;
       var data = (object[])e.Data.GetData(typeof(string[]));
    
       // causes error - if there is already data bound to the control
       //   see image below
       //dataGridView1.Rows.Insert(hitTest.RowIndex, data);
    
       DataTable dt = (DataTable) dataGridView1.DataSource;
       DataRow dr = dt.NewRow();
       dr.ItemArray = data;
       dt.Rows.Add(dr);
    }
    

    Error Message in DebugMode

    enter image description here

    worked fine for me – if any error shows up in your code, let me know

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to drop a now supposedly redundant file in SQL Server (2005), but
I want to import data from an Excel file - assume Excel 2003 /
I need to copy some data from one table to another in Oracle, while
I want to generate some data for editing, filtered by the choice a user
I have basically MySQL dump from a WordPress database with some data. The whole
I'm getting magical with some data filtering. When hitting a drop down list I
I have a myism table 'test' which holds some out-dated data, now I want
I'm working on a vertex shader in which I want to conditionally drop some
I have a view where I add some elements to a table from Database;
I am using a jQuery method $.getJSON to update data in some cascading drop

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.