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 / VB.NET / November 2006

Tip: Looking for answers? Try searching our database.

How to get a form's property value from a class?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dean Slindee - 22 Nov 2006 01:55 GMT
I have a form whose Property value I need to get at from a class (contained
in another project, same solution).

Here is the form's property:

  Private booIsInsert As Boolean = False

  Public Property IsInsert() As Boolean

     Get

        Return booIsInsert

     End Get

     Set(ByVal Value As Boolean)

        booIsInsert = Value

     End Set

  End Property

Here is the class's function that needs the property value:

  Public Shared Sub FormDataChanged(ByVal sender As System.Object)

     Dim frmParent As Form

     frmParent = sender.ParentForm

     If Not frmParent.IsInsert Then 'SYNTAX ERROR line

        Dim ctl As Control

        ctl = CType(frmParent.Controls.Item("btnUpdate"), Control)

        Call FrameButtonPaintFlat(frmParent, CType(ctl, Control)) 'green
frame around button

     End If

Syntax error message: "IsInsert is not a member of
System.Windows.Forms.Form"

I understand the error, but is there *any* way to reference the frmParent
instance and get the IsInsert property value?

Or some other approach?

Thanks in advance.

Dean S
RobinS - 22 Nov 2006 03:08 GMT
You probably need to add a reference to
the project containing the class in which
you want to access that form's property.
(Did you get that?)

To be clearer (I hope), an example:

1) Project 1, has Form1 with property IsInsert.
2) Project 2, has Class1 that wants to access
  Form1's property IsInsert.

Open Project2's properties and click on References.
THen click on Add. Choose the Projects tab, and
select Project1.

Then on the bottom of the screen, where it has
Imported Namespaces, find Project1 in the list
and check it (you'll have to click it twice).
Not Project1.My or Project1.My.Resources,
just Project1.

*Now* you should be able to access Form1.IsInsert.

Good luck.
Robin S.
----------------------------------------

>I have a form whose Property value I need to get at from a class (contained
>in another project, same solution).
[quoted text clipped - 49 lines]
>
> Dean S
Michael C - 22 Nov 2006 03:54 GMT
>I have a form whose Property value I need to get at from a class (contained
>in another project, same solution).

I'd suggest you're doing something wrong. In all my years of programming I
don't think I've ever done this or needed to do this. The form should pass
whatever information it needs to the class so the class can perform its
task. Can you explain more what you're doing?

If you really need to do this I'm presuming Robin's answer won't help
because the project with the form already has a reference to the project
with the class, so you can reference the other way. But what you can do is
define an interface in the project with the class and have the form
implement that interface.

Michael
RobinS - 22 Nov 2006 17:29 GMT
If you want project1 to reference something in project2,
you must add a reference to project1, even if project2
has a reference to project1. It's project-specific, and
project1 doesn't know about project2's reference to project1.
Did I use the word project in there enough times? ;-)

Robin S.
--------------------
>>I have a form whose Property value I need to get at from a class
>>(contained in another project, same solution).
[quoted text clipped - 11 lines]
>
> Michael
Michael C - 26 Nov 2006 22:07 GMT
> If you want project1 to reference something in project2,
> you must add a reference to project1, even if project2
> has a reference to project1. It's project-specific, and
> project1 doesn't know about project2's reference to project1.
> Did I use the word project in there enough times? ;-)

For a start you can't add a reference to an exe project. Even if both
projects were dlls I doubt you could add a circular reference. Even if you
could this would be bad practice. Which would you compile first?

Michael
RobinS - 26 Nov 2006 22:32 GMT
I assumed he was talking about having multiple project
inside one solution. If I misunderstood, then never mind. :-)

Robin S.
----------------------------------
>> If you want project1 to reference something in project2,
>> you must add a reference to project1, even if project2
[quoted text clipped - 7 lines]
>
> Michael
Michael C - 26 Nov 2006 23:15 GMT
>I assumed he was talking about having multiple project
> inside one solution. If I misunderstood, then never mind. :-)

He was. For projects in the same solution I doubt you can add a circular
reference.

Michael
RobinS - 27 Nov 2006 03:38 GMT
>>I assumed he was talking about having multiple project
>> inside one solution. If I misunderstood, then never mind. :-)
[quoted text clipped - 3 lines]
>
> Michael

Yes, you're absolutely right. I must have had some temporary
insanity going on there, to think that would work. My mistake.
Thanks for clarifying.

Robin S.
Cor Ligthert [MVP] - 22 Nov 2006 05:16 GMT
Dean,

I have almost the same idea as Michael, even more, it seems that you want to
give the property at a certain moment to the class. I think that than a
method is more sufficient because than the given data can be processed.

Cor

>I have a form whose Property value I need to get at from a class (contained
>in another project, same solution).
[quoted text clipped - 49 lines]
>
> Dean S

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.