Split from - http://www.daniweb.com/forums/thread37592.html

Hi,

I want to do following two steps. I am already done with first step. But I can't do the second step. Could anyone give me any idea how to do it?

Step 1: After serialization, I load XML file's data in a datagrid in tabular format.

Step2 : Now I want to add row in datagrid. And I want to save newly added data to same XML file.

Thanks

Neel

Edited 6 Years Ago by __avd: Split into a new thread.

>Now I want to add row in datagrid. And I want to save newly added data to same XML file.

Serialized that object. I don't think that there will be any problem.

Take a look at this sample,

namespace org
{
    public class Student
    {
        public int Roll { get; set; }
        public string Name { get; set; }
        public Student()
        {
            Name = string.Empty;
        }
        public Student(int roll, string name)
        {
            Name = name;
            Roll = roll;
        }
    }
    [XmlRoot("Students")]
    public class Students : List<Student>
    {
        
    }
}
org.Students s = null;

 void Serialize(){
            FileStream fs = new FileStream(@"file1.xml",FileMode.Create);
            XmlSerializer xr = new XmlSerializer(typeof(org.Students));
            xr.Serialize(fs,s);
            fs.Close();
  }
  void Deserialize() {
        {
            FileStream fs = new FileStream(@"file1.xml", FileMode.Open );
            XmlSerializer xr = new XmlSerializer(typeof(org.Students));
            s = (org.Students)xr.Deserialize(fs);
            fs.Close();
            // Adding a new student
            s.Add(new org.Student(3, "Mr. ABC"));
            dataGridView1.DataSource = s;
        }
This article has been dead for over six months. Start a new discussion instead.