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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:42:31+00:00 2026-06-12T02:42:31+00:00

I have two dataGridViews that load up an XML file each, I have made

  • 0

I have two dataGridViews that load up an XML file each, I have made it so that you can drag and drop rows in between each of the grids. However at the moment, all that it does is copy the data from the dataGridView. This works fine however I need to copy all of the XML that is relevant to that row.

Here is the XML that I have to work with:

<WindowBuilderProject>
  <stringtable>

    <stentry>0..607</stentry> //All of the other records

    <stentry>
      <index>608</index>
      <sid>MNUB_AUTO</sid>
      <val>
        <en>AUTO</en>
      </val>
      <params>
        <fontref>0</fontref>
        <numref>0</numref>
        <clip>FALSE</clip>
        <include>TRUE</include>
        <protected>FALSE</protected>
        <cwidth>-1</cwidth>
        <dwidth>0</dwidth>
      </params>
    </stentry>

  </stringtable>
</WindowBuilderProject>

So I need to copy the XML of the row that the user has selected and insert it into the in the other (same format) XML document.

So far I have this:

string location = "/WindowBuilderProject/stringtable/stentry[index='" + rowIndexOfItemUnderMouseToDrop + "']";
XmlNode Copy = xDoc.ImportNode(xDoc2.SelectSingleNode(location), false);
xDoc.DocumentElement.AppendChild(Copy); //This is just supposed to add it to the end, I will worry about ordering once it works

It runs fine, but all that happens i I get a added to the bottom of the XML file. How can I select the whole block of XML?

Thanks a lot for your help!

  • 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-12T02:42:32+00:00Added an answer on June 12, 2026 at 2:42 am

    Assume you want to copy block of elements from text1.xml to text2.xml, you can use LINQ to XML, example below assumes copying all entries from text1 to text 2:

      var xDoc1 = XDocument.Load("C:\\text1.xml");
      var xDoc2 = XDocument.Load("C:\\text2.xml");
    
      var doc1Entries = xDoc1.Descendants("stentry");
    
      var cloneEntries = doc1Entries.Select(x => new XElement(x));
      xDoc2.Descendants("stentry").Last().AddAfterSelf(cloneEntries);
    
      xDoc2.Save("C:\\text2.xml");
    

    But you also can use Where method to filter to get part of xml, sample below is to filter using list of indices:

      var filterIndices = new[] {600, 601, 700, 705};
    
      var doc1Entries =
          xDoc1.Descendants("stentry")
               .Where(x =>         
                   filterIndices.Contains(int.Parse(x.Element("index").Value)));
    

    In here, I assume to insert to the last using Last, but if you care about ordering, you can use LINQ on xDoc2 to find correct position, then do insert.

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

Sidebar

Related Questions

I have a windows form that has two DataGridViews (DGVs) that will hold 25,000+
Updated to be clear. Step One: I have a XML file that I want
I have two tables that are related to each other in a 1-1 relationship
I have two DataGridViews that have the same column schema (although two different DataViews
I have two files client.php and server.php. The client file send a HTTP request
I have two columns say Main and Sub . (they can be of same
Windows form application. C# 4.0. Basically I have two datagridviews dgv1 and dgv2. One
Would someone kindly assist me with the following? I have two DataGridView objects that
I have a TabControl on my Form with two pages. Each of pages contains
I have a C# program that selects data from two different database files and

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.