Guest User

Untitled

a guest
Dec 17th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. private void Deletbtn_Click(object sender, EventArgs e)
  2. {
  3. XmlNode node = doc.SelectSingleNode("//entry[@entryno='" + Dgv.CurrentRow.Cells[0].Value + "']");
  4.  
  5. try
  6. {
  7. if (node != null && Dgv.CurrentRow.Selected == true)
  8. {
  9. doc.DocumentElement.RemoveChild(node);
  10.  
  11. // Trying to refresh the sequence each time an node is deleted.
  12. int Attrno = int.Parse(doc.SelectSingleNode("//entry[@entryno]").Value);
  13. do
  14. {
  15. Attrno = 0;
  16. Attrno++;
  17. } while (Attrno < doc.ChildNodes.Count);
  18. doc.SelectSingleNode("//entry[@entryno]").InnerText = Attrno.ToString();
  19.  
  20. doc.Save(Application.StartupPath + @"SleepRecords.xml");
  21. }
  22. else
  23. MessageBox.Show("Click the left side of the grid to select a row to delete.", "Select row", MessageBoxButtons.OK, MessageBoxIcon.Information);
  24. }
  25. catch (Exception ex)
  26. {
  27. MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  28. }
  29. ReloadData();
  30. Resetbtn_Click(Deletbtn, e);
  31. makePdf();
  32. }
  33.  
  34. XmlNodeList nodes = doc.SelectNodes("//entry");
  35. int max = 0;
  36. foreach (XmlNode node in nodes)
  37. {
  38. int nodeAttr = int.Parse(node.Attributes["entryno"].Value);
  39. max = nodeAttr;
  40. }
  41. max++;
Add Comment
Please, Sign In to add comment