Hi aysrun,
How did you populate the DataGridView rows? Did you use data binding? Here is a very easy way to populate data from xml file and save data to it using data binding.
public partial class Form1 : Form
{
private DataTable dtSource = new DataTable("Table1");
public Form1()
{
InitializeComponent();
dtSource.Columns.Add("Column1", typeof(int));
dtSource.Columns.Add("Column2", typeof(string));
dtSource.ReadXml(@"D:\data.xml");
dataGridView1.DataSource = dtSource;
textBox1.DataBindings.Add("Text", dtSource, "Column1");
textBox2.DataBindings.Add("Text", dtSource, "Column2");
}
private void btnSave_Click(object sender, EventArgs e)
{
dtSource.WriteXml(@"D:\data.xml");
}
}
In this example, I use a DataTable, WriteXml and ReadXml will auto serialize/deserialize the data into/from an xml file.
Then bind the dtSource to the TextBox, when you click different rows, it will populate the selected rows data in the two textboxes.
If I misunderstood you, please feel free to tell me.
Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.