P
Peter Duniho
[...]
How can i get call getNode() and get a node object from Form1. Since
it is already open.
You just need the reference to the Form1 instance you've created.
1. I cannot create a new object for Form1 since it is already open
Well, you could create a new object for Form1 -- there's nothing to
stop you from having more than one instance of a given form class --
but of course the new instance wouldn't be the one with the data you
want.
2. One sol would be to have static class with nodeArray as a static
member. But won't i be violating the concepts of good object -
oriented programming?
Is the array something that would make sense as a static member? If
so, your current design is already flawed.
If it's not something that would make sense as a static member -- that
is, it really is specific to the form instance and if you did open
multiple instances of that form class, would you want the data separate
per-form? -- then making it static just to solve this issue definitely
wouldn't be a good idea.
Please suggest possible solutions. Damn!! I know OOP but not much of
C# and desktop development!!
Well, as I wrote to start with here: as things stand now, you simply
need to keep a reference to the form. There are a few different common
ways to deal with this:
* look for the form instance in the Application.OpenForms collection
* make the form a singleton, with a static accessor property
* pass the reference to the form to whatever object is going to
need it; for example, if your second form is what needs to access the
data, then a common technique is to pass the reference to the Form1
instance in the constructor when creating Form2.
Pete