Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何删除DataTable中所有选中的名称行?_C#_Datagridview_Items_Checkedlistbox - Fatal编程技术网

C# 如何删除DataTable中所有选中的名称行?

C# 如何删除DataTable中所有选中的名称行?,c#,datagridview,items,checkedlistbox,C#,Datagridview,Items,Checkedlistbox,我的datagridview中加载了一个xml文件。我加载到datagridview的文件如下所示: <?xml version="1.0" standalone="yes"?> <program> <group active="1" name="name3"> <item active="Active"> <id>

我的datagridview中加载了一个xml文件。我加载到datagridview的文件如下所示:

<?xml version="1.0" standalone="yes"?>
<program>
  <group active="1" name="name3">
    <item active="Active">
      <id>name3</id>
      <ip>223.26.0.0</ip>
      <names>jakas strona</names>
      <comment>komentarz</comment>
    </item>
    <item active="Active">
      <id>name3</id>
      <ip>223.26.0.0</ip>
      <names>jakas strona</names>
      <comment>komentarz</comment>
    </item>
  </group>
</program

之后还必须更新数据集,如 数据更新(hostsDataSet,“Temp”)

List rows_to_remove=new List();
//首先将匹配项添加到列表中,如
foreach(dt1.Rows中的数据行row1)
{
foreach(dt2.Rows中的数据行第2行)
{
if(row1[“Name”].ToString()==row2[“Name”].ToString())//将此处更改为复选框条件
{
行到行删除。添加(行1);
}
}
}
在这里输入代码
foreach(数据行中的行\u到\u在此删除输入代码)
{
dt1.行。删除(行);
dt1.AcceptChanges();
}
尝试hostsDataSet.Tables[“group”].AcceptChanges();
private void deleteButton_Click(object sender, EventArgs e)
{
    if (checkedListBox1.SelectedIndex == 1)
    {
        // string groupName = group.Attribute("name").Value;
        hostsDataSet.Tables["group"].Rows[0].Delete();
    }              
}
List<DataRow> rows_to_remove = new List<DataRow>();
//first add the match item to List like 

foreach (DataRow row1 in dt1.Rows)
{
    foreach (DataRow row2 in dt2.Rows)
    {
        if (row1["Name"].ToString() == row2["Name"].ToString())// change here as check box conditions
        {
            rows_to_remove.Add(row1);
        }
    }
}


    enter code here

foreach (DataRow row in rows_to_remoenter code hereve)
{
    dt1.Rows.Remove(row);
    dt1.AcceptChanges();
}