XML
<?xml version="1.0" encoding="utf-8"?>
<TrackCollection>
<Tracks>
<Id>1</Id>
<Artist>Artist 1</Artist>
<Album>His album</Album>
<Filepath>C://music//song.mp3</Filepath>
<Id>2</Id>
<Artist>Artist 1</Artist>
<Album>His album</Album>
<Filepath>C://music//song2.mp3</Filepath>
<Id>3</Id>
<Artist>Artist 1</Artist>
<Album>His album</Album>
<Filepath>C://music//song2.mp3</Filepath>
</Tracks>
</TrackCollection>
DataSet dsStore = new DataSet();
DataTable dt = new DataTable();
public void loadXmlTracks()
{
//TrackCollection tracks = null;
string path = "..//..//..//test.xml";
//XmlSerializer serializer = new XmlSerializer(typeof(TrackCollection));
//StreamReader reader = new StreamReader(path);
//tracks = (TrackCollection)serializer.Deserialize(reader);
//reader.Close();
dsStore.ReadXml(path);
dt = dsStore.Tables["Track"];
// finally bind the data to the grid
LoadGrid(dt);
}
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
int i;
int j;
i = e.RowIndex;
j = e.ColumnIndex;
string id = dataGridView1.Rows[i].Cells[0].Value.ToString();
string value = dataGridView1.Rows[i].Cells[j].Value.ToString();
DataRow[] row = dt.Select("Id=" + i, "Id");
foreach (DataRow r in row)
{
r[j] = value;
r.AcceptChanges();
}
public void LoadGrid(DataTable dt)
{
dataGridView1.DataSource = null;
dataGridView1.DataSource = dt;
}
EDIT: here's my xml file which is being loaded then I take that and insert into a datatable, then I use that datatable to load my datagridview. What I would like to accomplish is if a user edits a cell in the datagridview to update that row in my datatable so when i close the application it saves back to the XML file.
What I am not sure and can't figure out is how do I save that change back to my Datatable and is it correct to do a Loop if I have the ID of the row that needs to be changed?
I tried RowFilter and that made the change but when I reloaded my datagridview it only show the row I changed..