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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:21:49+00:00 2026-06-13T11:21:49+00:00

In my xml file,it has many elements and many child/sub child elements are there

  • 0

In my xml file,it has many elements and many child/sub child elements are there so i have decided to load as generic list and display in the DGView and the columns are already created/customed in DGview.

I have to edit the values in the datagridview and serialize back to the file. I would like to know,
how can i get the values from the datagrid view and serialize back to the file.

I tried using this, Dataset ds = new Dataset();ds = (Dataset) (dataGridView2.Datasource);ds.WriteXml("XML_File.xml"); i got a error message, nullRefExceptionError.
As I know the DataSet ds is null, thats why I’m getting this error.

I don’t want to use the dataset for binding.I want to bind the xml file directly to the datagridview. IS it possible with my approach???

This approach is good but it’s not saving the xml file as like the original xml file:

 DataTable dt = new DataTable("Rules");

        for (int i = 0; i < dataGridView4.ColumnCount; i++)
        {
            dt.Columns.Add(dataGridView4.Columns[i].Name, typeof(System.String));
        }

        DataRow myrow;
        int icols = dataGridView4.Columns.Count;
        foreach (DataGridViewRow drow in this.dataGridView4.Rows)
        {
            myrow = dt.NewRow();
            for (int i = 0; i <= icols - 1; i++)
            {

                myrow[i] = drow.Cells[i].Value;
            }
            dt.Rows.Add(myrow);
        } 

        dt.WriteXml(@"C:\test\items.xml");

Any help for me to serilaize/write the values from datagridview.

  • 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-13T11:21:50+00:00Added an answer on June 13, 2026 at 11:21 am

    I have adapted this approach for my problem & it works.

    List<Test>laneConfigs = new List<Test>();//From a class
                foreach (DataGridViewRow dr in dataGridView1.Rows)
                {
                    int bbbBorder = 0;
                    Int32.TryParse(dr.Cells["BBor"].Value.ToString(), out bbbBorder );
                    int eeee= 0;
                    Int32.TryParse(dr.Cells["EBor"].Value.ToString(), out eee);
    
                    LaneConfig laneConfig = new LaneConfig(
                        dr.Cells["ID"].Value.ToString(),
                        (TrafficLaneType)Enum.Parse(typeof(TrafficLaneType), dr.Cells["Type"].Value.ToString()),
                        new ValueWithUnit<int>(bbbBorder, "mm"),
                        new ValueWithUnit<int>(eee, "mm"));
    
                    laneConfigs.Add(llaneConfig);
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file that has many xml-like elements such as this one: <document
I have an XML file which has many section like the one below: <Operations>
I have an xml file which has many numbers which are formatted incorrectly in
I have a text file that has many records. Each record is a xml
I have seen in many XML file has the data inside this <![CDATA[ ]]>
I have this xml file which has text init. i.e Hi my name is
I have an XML file that has a number of nodes, each of which
I have an XML file which has to be transformed using XSLT, I am
I have an xml file that has an address node that looks like <address>
I have a very large XML file which has like 40000 data, and when

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.