We help IT Professionals succeed at work.

How do I call a method from another method?

Antonio King
Antonio King asked
on
274 Views
Last Modified: 2010-04-15
How do I call this...
        private void UpdateListBox(object sender, EventArgs e)
        {
        }
... from another method?
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
If you aren't doing anything with "sender" or "e" in UpdateListBox, you can just pass in null to both.

UpdateListBox(0, 0);

If you actually use that data, then you need to get the listbox itself to trigger that event, which will pass sender and e properly.
CERTIFIED EXPERT

Commented:
UpdateListBox(sender,Eventargs.empty)
Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009

Commented:
is that method a member of a class? is that class a static class?
is the "other" method in the same class?

as the method is private, you can "only" call it from the same class.

you might want to specify what exactly is the "problem" you have, for example, what to pass as arguments?
CERTIFIED EXPERT

Commented:
You can do like this

Whatever inside the updatelistbox ,put all that in new methid as it is NewMethod()
and call that from another method

  private void UpdateListBox(object sender, EventArgs e)
        {
             NewMethod()
        }

 NewMethod()
{
  //Code here
}

Jai STech Arch

Commented:
it is much better to use
(this, new EventArgs()); rather than (0,0)
also if you want to pass your own event arguements ...
create a event arugment and assign it with your values and then pass it along...
EventArgs ev = new EventArgs(something);
(this,ev)
Antonio KingIT Manager

Author

Commented:
Thanks all for your eager responses!

Commented:
>> it is much better to use
>> (this, new EventArgs()); rather than (0,0)

That depends on what they are doing inside of the event handler. If all that is occuring is setting a flag (bComplete = true), then it really doesn't matter. :) Of course, if they're using the args, then neither will help, since an empty arg set is arguably as useless as the null arg set (assuming you handle that).
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.