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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:17:11+00:00 2026-06-12T22:17:11+00:00

I know this is a very simple and basic question but I would like

  • 0

I know this is a very simple and basic question but I would like to know how to fix this. I got a problem in serializing the object from the datagrdiview.

This line is not working for me in the

if (dataGridView1 != null) 
    _example.Details = dataGridView1.DataBindings;   // Not Working.

Please tell me what is the mistake I’m doing here…! Thank you.

private void button3_Click(object sender, EventArgs e)  //Read
{
            XmlSerializer _serializer = new XmlSerializer(typeof(XMLExample));
            XMLExample _example = new XMLExample();

            // Read file.
            using (TextReader textReader = new StreamReader(@"C:\test\testserialization.xml"))
            {
                _example = (XMLExample)_serializer.Deserialize(textReader);
                textReader.Close();
            }

            textBox1.Text = _example.ID;
            textBox2.Text = _example.Initial;

            dataGridView1.DataSource = _example.Details;
        }

        private void button2_Click(object sender, EventArgs e) //Write
        {
            XmlSerializer _serializer = new XmlSerializer(typeof(XMLExample));
            XMLExample _example = new XMLExample();

            _example.ID = textBox1.Text;
            _example.Initial = textBox2.Text;

            List<Detail> _source = new List<Detail>();

            for (int i = 0; i < 10; i++)
            {
                _source.Add(new Detail
                {
                    FirstName = "Name_" + i,
                    LastName = "Surname_" + i,
                    Section = "section_"+i,
                });
            }

            dataGridView1.DataSource = _source;

            if (dataGridView1 != null && dataGridView1.DataSource != null) 
               _example.Details = (List<Detail>)dataGridView1.DataSource;

            using (TextWriter textWriter = new StreamWriter(@"C:\test\testserialization.xml"))
            {
                _serializer.Serialize(textWriter, _example);
                textWriter.Close();
            }
        }

The class file:

[Serializable]
public class StudentInfo : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    public string UserID { get; set; } // Textbox1
    public string Department { get; set; } // Textbox2
    public List<Detail> Details { get; set; }
}

[Serializable]
public class Detail // Datagridview1
{
    [XmlElement("FirstName")] //Datagridview
    public string FirstName { get; set; }
    [XmlElement("LastName")] //Datagridview
    public string LastName { get; set; }
    [XmlElement("Section")] //Datagridview
    public string Section { get; set; }
}
  • 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-12T22:17:14+00:00Added an answer on June 12, 2026 at 10:17 pm

    Try this:

    if (dataGridView1 != null && dataGridView1.DataSource != null) test.Details = (List<Detail>)dataGridView1.DataSource;
    

    Sample code with assignment List<Detail> to property DataSource of DataGridView object (add this code in constructor):

     List<Detail> _source = new List<Detail>();
                for (int i = 0; i < 10; i++)
                {
                    _source.Add(new Detail
                    {
                        FirstName = "Name_" + i,
                        LastName = "Surname_" + i,
                        Section = "Section_" + i
                    });
                }
    
                dataGridView1.DataSource = _source;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is probably a very simple question but how would I do
This may be very simple question,But please help me. i wanted to know what
I know this is very basic. I would like to use jQuery to change
This seems to me like a very simple question, but I can't seem to
I know this is a very basic question but I have kinda been thrown
I know it might be a very simple solution for this, but I am
I know this is very evil, but is it possible to add an object
I know this is a very broadly scoped question, but what do I need
I know, is a very basic question, but I am in the process of
I know this question might be repeated many times but would really appreciate any

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.