//WHEN BUTTON IS CLICKED private void buttonOK_Click(object sender, EventArgs e) { //SAVE THE TEXT FROM TEXT BOX TO NAME OF NEW FAVORITE ModifyFavorites.NameOfNewFavorite = textBoxNewName.Text; //CLOSE THIS FORM ModifyFavorite f1 = (ModifyFavorite)Application.OpenForms["ModifyFavorite"]; f1.Close(); }
//MODIFY NAME OF THE FAVORITE private void button1_Click(object sender, EventArgs e) { int selectedIndex = dataGridView1.SelectedRows[0].Index; ModifyFavorite obj = new ModifyFavorite(); obj.ShowDialog(); dataGridView1[1, selectedIndex].Value = NameOfNewFavorite; //selectedIndex = dataGridView1.CurrentRow.Index; string rowID = dataGridView1[0, selectedIndex].Value.ToString(); XDocument document = XDocument.Load("myFavorites.xml"); //using linq var pageInfo = (from xml in document.Descendants("Details") where xml.Element("Fav_ID").Value == rowID select xml).FirstOrDefault(); pageInfo.Element("Name").Value = NameOfNewFavorite; document.Save("myFavorites.xml"); }