Hi Darkblue,
I came to that conclusion, but still it seems odd to me that the click
method is being called twice. Are there any known issues with custom controls
derived from System.Windows.Forms.Button?
"darkblue progger" wrote:
> hi!
>
> for that i would ask 'if(lvSources.SelectedItems.Count > 0){...}' ...
> and i would disable the button at beginning method and enable (if
> items-Count > 0) it at the end of the click-method
>
> ciao
>
> "Vincent" wrote:
>
> > 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;
> > }
> > }
|