Click here to Skip to main content
15,887,318 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: How do I execute a class from a class? Pin
Charlie Williams31-Jan-05 8:36
Charlie Williams31-Jan-05 8:36 
GeneralRe: How do I execute a class from a class? Pin
DSLR31-Jan-05 10:22
DSLR31-Jan-05 10:22 
GeneralRe: How do I execute a class from a class? Pin
Charlie Williams31-Jan-05 11:38
Charlie Williams31-Jan-05 11:38 
GeneralRe: How do I execute a class from a class? Pin
DSLR31-Jan-05 11:47
DSLR31-Jan-05 11:47 
GeneralRe: How do I execute a class from a class? Pin
Charlie Williams31-Jan-05 12:00
Charlie Williams31-Jan-05 12:00 
GeneralRe: How do I execute a class from a class? Pin
DSLR31-Jan-05 12:09
DSLR31-Jan-05 12:09 
GeneralRe: How do I execute a class from a class? Pin
Charlie Williams31-Jan-05 12:48
Charlie Williams31-Jan-05 12:48 
AnswerRe: How do I execute a class from a class? Pin
Charlie Williams31-Jan-05 13:53
Charlie Williams31-Jan-05 13:53 
Ok, I went back and looked at the code you posted (against my better judgement, but what the heck).

It turns out the NullReferenceException you had originally asked about was a symptom of a questionable design. That's why pointing out the source of the exception didn't really solve your problem.

Let's see if I have this correct. You have a Form with two Panel controls. Each Panel contains a class which represents a group of controls (Array1 in Panel1 and Array2 in Panel2). When a button is clicked in Array1 on Panel1, you want something to happen in Array2 on Panel2. Do I have it right?

Ok, the original problem you posted with was that you got a NullReferenceException when you clicked a buttin in Array1. The reason was that you were creating a new instance of Array2 instead of using the one you intended to, which is the one on Panel2 on Form1.

One way of solving your problem would be giving the instance of Array1 a reference to the intance of Array2. I personally think this would be kind of clunky because Array1 shouldn't need to have any knowledge of Array2.

Since you are wanting to do something in an unrelated class (Array2) when something happens in Array1, I think this would be the ideal place for an event. Declare an event in Array1 which gets fired anytime a button is clicked. You can define a class that inherits from EventArgs if there is additional information that you'd like to pass along when the event is fired (index of the button clicked, etc.) If you define an event args class, you'll also need to define a delegate that the handlers of this event will use as a signature. You can then define an event handler in Array2 that handles this event.

Once you've got that all set up, an object common to both classes (Form1, for instance) would hook the event up after instantiating both ojects and you're good to go.

If you have questions about the way events work in VB.NET, I'd suggest MSDN or Google, which are both excellent resources. If you have a specific question about any of my suggestions, ask away. Please don't ask me to write the code, though.

Charlie

if(!curlies){ return; }
GeneralRe: How do I execute a class from a class? Pin
DSLR31-Jan-05 23:58
DSLR31-Jan-05 23:58 
GeneralRe: How do I execute a class from a class? Pin
Charlie Williams1-Feb-05 4:47
Charlie Williams1-Feb-05 4:47 
GeneralRe: How do I execute a class from a class? Pin
DSLR1-Feb-05 8:27
DSLR1-Feb-05 8:27 
QuestionInstall or at least read an HxS ? Pin
Denevers30-Jan-05 3:39
Denevers30-Jan-05 3:39 
GeneralCrystal Reports and .Net Remoting Pin
a_dipendra28-Jan-05 4:40
a_dipendra28-Jan-05 4:40 
GeneralInstalling a publisher policy into the GAC Pin
Pain_Elemental28-Jan-05 4:29
Pain_Elemental28-Jan-05 4:29 
GeneralHash Storage Problem Pin
SusmithaC28-Jan-05 1:04
SusmithaC28-Jan-05 1:04 
GeneralRe: Hash Storage Problem Pin
Philip Fitzsimons28-Jan-05 4:40
Philip Fitzsimons28-Jan-05 4:40 
General.wav files Pin
ziggy8227-Jan-05 5:11
ziggy8227-Jan-05 5:11 
GeneralRe: .wav files Pin
Corinna John31-Jan-05 21:04
Corinna John31-Jan-05 21:04 
GeneralTesting Tool for .Net Pin
Vishwanathkk27-Jan-05 2:34
Vishwanathkk27-Jan-05 2:34 
Generalstring to long Pin
zagzagzag27-Jan-05 0:46
zagzagzag27-Jan-05 0:46 
GeneralRe: string to long Pin
wyoung7631-Jan-05 23:18
wyoung7631-Jan-05 23:18 
GeneralRemoving an assembly from the GAC Pin
shayw26-Jan-05 8:24
shayw26-Jan-05 8:24 
GeneralRe: Removing an assembly from the GAC Pin
Mike Dimmick27-Jan-05 4:25
Mike Dimmick27-Jan-05 4:25 
GeneralRe: Removing an assembly from the GAC Pin
shayw27-Jan-05 19:25
shayw27-Jan-05 19:25 
GeneralRe: Removing an assembly from the GAC Pin
GuruPandian29-Jan-05 3:34
GuruPandian29-Jan-05 3:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.