-1

I have an xml file loaded into my datagridview. The file that I load into datagridview looks like this:

<?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

In my program I have checkedlistbox which contains group names "name1", "name2", etc. My code in delete button delete first group name on the checkedlistbox + all rows which contains this name group. I want to modify my button to delete selected checkedlistbox item(name of group) and all rows which contain this group name. I hope I explained in more clearly. This is my delete button code:

private void deleteButton_Click(object sender, EventArgs e)
{
    if (checkedListBox1.SelectedIndex == 1)
    {
        // string groupName = group.Attribute("name").Value;
        hostsDataSet.Tables["group"].Rows[0].Delete();
    }              
}
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
speedvees
  • 117
  • 1
  • 11

2 Answers2

0

You have to also update dataset after that like da.Update(hostsDataSet, "Temp");

Pramod
  • 96
  • 7
0
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();
}
Pramod
  • 96
  • 7