Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

communication between classes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
doofy - 02 Mar 2008 15:56 GMT
This is a conceptualization problem for me regarding how
classes/namespaces share information.  I can't really return an
object/value back from a called class to a calling class by directly
naming the calling class instance in the called class, as this violates
object oriented guidelines, as I understand them.

Here's the issue.

I'm creating a custom control which will be a tree view that holds table
and field names from an identified database.  I have a tree view as the
main control, with a context menu included.  In order to get the
information to fill the tree view, I created a small form within the
custom control project.  It shows up as a separate namespace within the
project.  I don't know how to pull this into the tree view namespace.

Within the form, there is a list box which allows multiple selections.
When I hit the OK button, I need to pass the selected table names back
to the tree view control.

If these were in the same namespace, I could probably just reference a
private variable that they share, but I don't know how to move that form
into the namespace.  It automatically created a new namespace for the form.

The other way, I assume, would be to pass some variable/object by
reference into the form control, then populate that object on closing
the form.

Right now I'm just anticipating using one long string with semi-colon
delimited table names, then parsing this out on the calling side.

Will I run into problems with that issue about not being able to change
strings, but having to create a new one each time? This could be a
problem when operating between namespaces.

Or do I need to use the StringBuilder feature (I've seen this referenced
in VB.NET, not sure about C#).

That's a lot of questions.  Any help would be appreciated.
Peter Duniho - 02 Mar 2008 20:30 GMT
> This is a conceptualization problem for me regarding how  
> classes/namespaces share information.  I can't really return an  
[quoted text clipped - 10 lines]
> custom control project.  It shows up as a separate namespace within the  
> project.  I don't know how to pull this into the tree view namespace.

This particular part of your question is easy, as you do it just as you do  
it with any of the other classes not in your calling class's namespace  
(i.e. every single .NET class you are using).  You use the "using"  
statement, or qualify the class name explicitly when you use it (e.g.  
"MyNamespace.MyClassName").

> Within the form, there is a list box which allows multiple selections.  
> When I hit the OK button, I need to pass the selected table names back  
> to the tree view control.

This is really a different question, actually.  Here, it's more about the  
correct way to expose data entered in the form to the code that displayed  
the form.  Even if the form were in the same namespace, that question  
would exist.

> If these were in the same namespace, I could probably just reference a  
> private variable that they share, but I don't know how to move that form  
> into the namespace.  It automatically created a new namespace for the  
> form.

How did you create the form?  Normally, if you use the designer to add a  
new form to your project, it will put the form in the same namespace.  Is  
the form in its own project as well?

Not that this matters _too_ terribly much.  It's just, as you've seen,  
more convenient if the form is in the same project/namespace.

As far as referencing a private variable, no...even in the same namespace,  
you can't reference a private variable in a different class.  But you're  
on the right track.  :)

> The other way, I assume, would be to pass some variable/object by  
> reference into the form control, then populate that object on closing  
> the form.

Passing by reference works only if you stay in the same call.  So, if  
you've added a method to the form to show it modally, yes...you can pass a  
variable by reference to that method, and then when the form is closed,  
that method would return having copied the data to the variable passed by  
reference.

An alternative would be to provide a property on the form that retrieves  
the data.  You can either populate a private field when the form is  
closed, inside the form class itself, and then return the value held in  
the private field, or you can simply have the property get the necessary  
data directly from the form's list box.  Either would be fine.

> Right now I'm just anticipating using one long string with semi-colon  
> delimited table names, then parsing this out on the calling side.

I would just return an array of strings, but if you really want to return  
a single string I suppose you could.

> Will I run into problems with that issue about not being able to change  
> strings, but having to create a new one each time? This could be a  
> problem when operating between namespaces.

I don't see how the two issues are connected at all.  The namespace issue  
is simply one of identifying types.  It has nothing to do with whether  
you'd need to create a new string from an existing one.

> Or do I need to use the StringBuilder feature (I've seen this referenced  
> in VB.NET, not sure about C#).

StringBuilder could in fact be useful if you really want to concatenate  
the list box items into a single string.  But I think you'd be better of  
just passing back an array.

Pete
doofy - 03 Mar 2008 02:26 GMT
>> This is a conceptualization problem for me regarding how  
>> classes/namespaces share information.  I can't really return an  
[quoted text clipped - 81 lines]
>
> Pete

Thanks for all of this.  I need to digest it.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.