【发布时间】:2015-07-02 20:38:01
【问题描述】:
我在 xml 中有一个数据库,我的 xml 文件是:
<?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>
我的 c# 代码用于从 DataGridView 和 xml 文件中删除一行。但是,如果我从 DataGridView 中选择任何行并按下删除按钮,我的代码总是会删除第一行。
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();
}
我想要在按钮单击事件 上仅删除一个选定行的代码
【问题讨论】:
标签: c# xml datagridview