[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 668
  • Last Modified:

C# GUI program in Visual Studio 2005: can a user control use a public variable of its parent form?

Hi Experts:

    I am working on a Visual Studio 2005 C# project.
    I have a user defined control, which is used by a form (note that they are in different .CS files, but in the same name space). There is DataGridView inside the user control, and I wanted to let an event handler of this DataGridView read a public variable member of the parent form. However, that variable is not recogonized in the event handler.
    Does it mean that the scope of the parent form public variable does not include the event handlers of the user control?
    Thank you!
0
huangs3
Asked:
huangs3
  • 2
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
That's correct.  You would need to either:

(1) Pass a reference to the Form INTO the UserControl.
(2) Make the Form Variable a STATIC member so it can be accessed from anywhere.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Obviously there are other options if you change your design...
0
 
huangs3Author Commented:
changing the Form variable to STATIC doesn't help. I am thinking about alternative decide. Any idea?
0
 
huangs3Author Commented:
I found STATIC variable in the FORM works now, and trying to find other alternative.
Idle Mind already answered my question completely.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now