PC Review


Reply
Thread Tools Rate Thread

Button executes twice?

 
 
=?Utf-8?B?VmluY2VudA==?=
Guest
Posts: n/a
 
      17th Mar 2005
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;
}
}
 
Reply With Quote
 
 
 
 
=?Utf-8?B?ZGFya2JsdWUgcHJvZ2dlcg==?=
Guest
Posts: n/a
 
      17th Mar 2005
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;
> }
> }

 
Reply With Quote
 
=?Utf-8?B?VmluY2VudA==?=
Guest
Posts: n/a
 
      17th Mar 2005
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;
> > }
> > }

 
Reply With Quote
 
=?UTF-8?B?TWFyY2luIEdyesSZYnNraQ==?=
Guest
Posts: n/a
 
      17th Mar 2005
Hi Vincent,

I think that your problem lies not in the handler's method.
It seems that you've assign the same event handler twice to
the "Click" event.

HTH
Marcin

> 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;
> }
> }

 
Reply With Quote
 
=?Utf-8?B?VmluY2VudA==?=
Guest
Posts: n/a
 
      17th Mar 2005
Hi Marcin,

I did a Find in Visual Studio on btnRemove.Click but I can only find it once.
Are there any other places except in the form where this can be done?

Thanks,
Vincent
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command button executes without code??? Pierre Microsoft Excel Programming 4 16th Aug 2008 02:54 PM
Convert SQl to VBA so that it executes in VBA RB Smissaert Microsoft Excel Programming 4 31st Aug 2007 01:59 PM
Where does a query really executes? Jordi Rico Microsoft ADO .NET 6 26th Sep 2005 04:13 PM
button click executes postback page not valid John Bonds Microsoft ASP .NET 5 4th Aug 2004 09:26 AM
Application_End never executes Pedro Duque Microsoft C# .NET 1 5th Nov 2003 03:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:34 PM.