Click event seems to fire multiple times

D

DEK

Stepping through my code the click eventhandler code
executes through a few times before it finally stops.
Even though I only click the button once, is there a reason
for this, I have a few if else and method calls in the
eventhandler.
 
N

Nicholas Paldino [.NET/C# MVP]

DEK,

Are these method calls doing anything that could trigger the click
event? Is your click event handler hooked up to multiple event handlers and
then you are calling other methods that could possibly cause those events to
be fired?

Can you post some sample code?
 
D

DEK

DEK,

Are these method calls doing anything that could trigger the click
event? Is your click event handler hooked up to multiple event handlers and
then you are calling other methods that could possibly cause those events to
be fired?

Can you post some sample code?
MainForm is a singleton form, InfoView is a user control.
the class is a panel of buttons and has methods to set them
enabled/disabled in certain ways, I.e. (this.ShowAddEditButtons).

private void add_Click(object sender, EventArgs e)
{
MainForm form = MainForm.GetInstance();
Contestant contestant = form.CurrentNode.Tag as Contestant;

// Root View
if (!form.InfoView.Visible && form.TableListView.Visible)
{
form.TableListView.Visible = false;
form.InfoView.Visible = true;

form.InfoView.Table = contestant.Blank.Tables
[Constants.Info];

form.InfoView.HeadingCat = "Adding a new";
form.InfoView.RefreshControl(true);
}

// Composite View
else if(form.InfoView.Visible && form.TableListView.Visible)
{
form.TableListView.Visible = false;
form.InfoView.Table = Season.GetInstance
(null).Individuals.Blank.Tables[Constants.Info];

form.InfoView.HeadingCat = contestant.Name + " - Adding a
new";

form.InfoView.RefreshControl(true);
}

// Change button views
this.ShowAddEditButtons();
form.InfoView.Focus();

}
 
D

DEK

DEK,

Are these method calls doing anything that could trigger the click
event? Is your click event handler hooked up to multiple event handlers and
then you are calling other methods that could possibly cause those events to
be fired?

Can you post some sample code?
MainForm is a singleton form, InfoView is a user control.
the class is a panel of buttons and has methods to set them
enabled/disabled in certain ways, I.e. (this.ShowAddEditButtons).

private void add_Click(object sender, EventArgs e)
{
MainForm form = MainForm.GetInstance();
Contestant contestant = form.CurrentNode.Tag as Contestant;

// Root View
if (!form.InfoView.Visible && form.TableListView.Visible)
{
form.TableListView.Visible = false;
form.InfoView.Visible = true;

form.InfoView.Table = contestant.Blank.Tables
[Constants.Info];

form.InfoView.HeadingCat = "Adding a new";
form.InfoView.RefreshControl(true);
}

// Composite View
else if(form.InfoView.Visible && form.TableListView.Visible)
{
form.TableListView.Visible = false;
form.InfoView.Table = Season.GetInstance
(null).Individuals.Blank.Tables[Constants.Info];

form.InfoView.HeadingCat = contestant.Name + " - Adding a
new";

form.InfoView.RefreshControl(true);
}

// Change button views
this.ShowAddEditButtons();
It was this last line^^^^

That method called refreshControl which reattached all the handlers
again, I moved the attaching of handlers to the constructor so they only
attached once, thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top