Click event seems to fire multiple times

  • Thread starter Thread starter DEK
  • Start date Start date
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.
 
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?
 
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();

}
 
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.
 
Back
Top