Hi,
Below, a complete example to help your problem. I used one column in this example.
using System.IO;
using System.Xml;
......
DataSet ds = new System.Data.DataSet();
string str = @"C:\your_path\PARTICIPANTS.xml";
private void btn_delete_Click(object sender, EventArgs e)
{
ds.Tables["PARTICIPANTS"].Rows[this.dgvxml.CurrentCell.RowIndex].Delete();
ds.Tables["PARTICIPANTS"].AcceptChanges();
this.Write_Xml();
}
private void Open_Xml()
{
DataTable dtable = new System.Data.DataTable("PARTICIPANTS");
dtable.Columns.Add("NAME");
ds.Merge(dtable);
if (File.Exists(str))
{
using (Stream stream_xml = new FileStream(str, FileMode.Open, FileAccess.Read))
{
ds.Tables["PARTICIPANTS"].ReadXml(stream_xml);
}
}
else
{
this.Write_Xml();
}
dgvxml.DataSource = ds.Tables["PARTICIPANTS"];
}
private void Write_Xml()
{
XmlTextWriter stwxml = new XmlTextWriter(str, System.Text.Encoding.UTF8);
ds.Tables["PARTICIPANTS"].WriteXml(stwxml, XmlWriteMode.IgnoreSchema, false);
stwxml.Close();
}
private void Form3_Load(object sender, EventArgs e)
{
this.Open_Xml();
}
private void btn_add_Click(object sender, EventArgs e)
{
DataRow drow = ds.Tables["PARTICIPANTS"].NewRow();
drow["NAME"] = txt_name.Text;
ds.Tables["PARTICIPANTS"].Rows.Add(drow);
dgvxml.DataSource = ds.Tables["PARTICIPANTS"];
this.Write_Xml();
}
private void dgvxml_CellClick(object sender, DataGridViewCellEventArgs e)
{
this.txt_name.Text = ds.Tables["PARTICIPANTS"].Rows[e.RowIndex]["NAME"].ToString();
}