I have a database in xml my xml file is:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--This is an XML Generated File-->
<Categories>
<Category>
<CategoryId>1</CategoryId>
<CategoryName>jitu</CategoryName>
</Category>
<Category>
<CategoryId>2</CategoryId>
<CategoryName>ansul</CategoryName>
</Category>
<Category>
<CategoryId>3</CategoryId>
<CategoryName>satish</CategoryName>
</Category>
<Category>
<CategoryId>4</CategoryId>
<CategoryName>tipu</CategoryName>
</Category>
</Categories>
My c# code is following for deleting a row from DataGridView and xml file. But my code always delete first row if I select any row from DataGridView and press the delete button.
private void btnDelete_Click(object sender, EventArgs e)
{
XmlDocument xdoc = new XmlDocument();
string PATH = "xmldata.xml";
ds.Clear();
dtgvCategory.Refresh();
ds.ReadXml(PATH);
row = ds.Tables[0].Rows[0];
int selectedRow = dtgvCategory.SelectedRows.Count;
if (selectedRow > 0)
{
row.Delete();
}
ds.WriteXml(PATH);
ds.AcceptChanges();
}
I want code that delete only one selected row on button click event