473,394 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Button executes twice?

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;
}
}
Nov 16 '05 #1
4 1588
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;
}
}

Nov 16 '05 #2
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;
}
}

Nov 16 '05 #3
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;
}
}

Nov 16 '05 #4
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
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Michael Johnson Jr. | last post by:
I am trying to handle a button click event, which updates a web control table with data. The button is dynamically created in the table itself. When I call updateTable() in the Page_Load the new...
3
by: erdem | last post by:
hi, i have a problem with asp.net when i was debugging i put breakpoint to pageload event and then i discovered that page is loaded once (explorer shows full page correctly but continues...
0
by: Oz | last post by:
Hi Using VS.NET 2003, Windows XP SP1, We have a page which has been developed using ASP.NET. On it, is a button which when clicked is supposed to add some data to a table. When the button is...
3
by: Imran Aziz | last post by:
Hello All, I have a search text and button that post data and my button handler filters the repeater control. However when the button is clicked the first time. The page_load event is being called...
0
by: Diffident | last post by:
Hello All, I have an asp:button and I have tied an eventhandler to this button's click event which means that the eventhandler should be executed everytime I click the button. But to my...
0
by: rajendra.mishra | last post by:
Hi... I have a frame(Report.htm) which has two aspx pages one for header(header.aspx) and the other for displaying reports(Report.aspx). when Report.htm is called Report.aspx executes twice. I...
9
by: mosscliffe | last post by:
I am sorry but I am all very new and slow at understanding all this ASP.NET2. I found some code which showed how to page with a repeater. All very excited as I had been looking for this all...
4
by: Aleks Kleyn | last post by:
In asp.net I can put code for button click event. However I come to this event twice. What is the reason and how to prevent or check second entry to this event. I need to make sure that i do not...
4
by: Tom Van den Brandt | last post by:
Hi, I wrote a simple windows service that includes a FileSystemWatcher. After building and installing the service (installutil) I notice that the service executes twice. I included a write to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.