G
Guest
Hello all,
I have an application that has a ListView and a DataSet. When btnRemove is
clicked, the method btnRemove_Click is being fired, which compares 2 keys to
find a unique match on a dataRow which then should be removed, through a
foreach loop and then the loop is being exited by break statement.
The problem is that for some reason, my (custom control) button is being
fired again, which may trigger an Exception since there might not be any
records left in the DataSet and ListView.
Below is the snippet of btnRemove_Click(object sender, EventArgs e)
Any thoughts why this is being fired twice?
Muchly appreciated,
Vincent
// Reference the selected ListViewItem
ListViewItem lvi = new ListViewItem();
lvi = lvSources.SelectedItems[0];
// Loop through the DataSet and find the corresponding record.
foreach(DataRow row in dsMaster.Tables["SrcTable"].Rows)
{
if(row["Source"].Equals(lvi.SubItems[0].Text) &&
row["OrigSource"].Equals(lvi.SubItems[1].Text))
{
row.Delete();
lvSources.Items.Remove(lvi);
dsMaster.Tables["SrcTable"].AcceptChanges();
return;
}
}
I have an application that has a ListView and a DataSet. When btnRemove is
clicked, the method btnRemove_Click is being fired, which compares 2 keys to
find a unique match on a dataRow which then should be removed, through a
foreach loop and then the loop is being exited by break statement.
The problem is that for some reason, my (custom control) button is being
fired again, which may trigger an Exception since there might not be any
records left in the DataSet and ListView.
Below is the snippet of btnRemove_Click(object sender, EventArgs e)
Any thoughts why this is being fired twice?
Muchly appreciated,
Vincent
// Reference the selected ListViewItem
ListViewItem lvi = new ListViewItem();
lvi = lvSources.SelectedItems[0];
// Loop through the DataSet and find the corresponding record.
foreach(DataRow row in dsMaster.Tables["SrcTable"].Rows)
{
if(row["Source"].Equals(lvi.SubItems[0].Text) &&
row["OrigSource"].Equals(lvi.SubItems[1].Text))
{
row.Delete();
lvSources.Items.Remove(lvi);
dsMaster.Tables["SrcTable"].AcceptChanges();
return;
}
}