473,808 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing form controls

M K
I have 2 classes. One where the form resides and I created another one for
all the database stuff.

after i get data from the db i want to be able to update the form. I have
the namespace of where the form code is but how do i get to the controls
themselves.

newbie in the class world.. still trying to figure it all out :)

Thanks for any help...
Jul 3 '07 #1
3 2219
On Tue, 03 Jul 2007 14:40:59 -0700, M K <sk************ ********@yahoo. com>
wrote:
I have 2 classes. One where the form resides and I created another one
for
all the database stuff.

after i get data from the db i want to be able to update the form. I
have
the namespace of where the form code is but how do i get to the controls
themselves.
Well, the "cheesy" way is to simply change the member fields for the
controls so that their access is public instead of private.

But it would be much better to expose the aspects of those controls that
you want to allow access to as properties or in some cases methods.
Those, you make a part of the public API that the form class exposes,
allowing the form class complete control over what client's of the form
class can do, rather than handing over the actual instance to the controls
(which provides implementation details that only the form should know
about).

Pete
Jul 3 '07 #2

"M K" wrote:
I have 2 classes. One where the form resides and I created another one for
all the database stuff.

after i get data from the db i want to be able to update the form. I have
the namespace of where the form code is but how do i get to the controls
themselves.

newbie in the class world.. still trying to figure it all out :)

Thanks for any help...
The management class needs to have a reference to the Form!
As the management class is supposed to be only once in memory, I would make
a singelton out of it. This provides a static method which returns the
instance of the class.
Once the Form has the reference to the management class it could pass their
own reference to the manager over an property
management class code:
private Form1 _myform;
public Form1 MyForm
{
get
{
return _myform;
}
set
{
if(value!=_myfo rm)
{
_myform = value;
}
}
}

Over this reference the managementclass cann then set public Properties or
call public methods with aproprtiat parameter, to modify the GUI.

If you are running the management class in an seperate thread from the GUI
you have to Invoke those methods.

Hope it helps,

All the best,

Martin
Jul 4 '07 #3
M K
ouch.. all those technical terms I dont understand yet...
talk about trying to confuse me.. i thought putting the word 'newbie' would
be a dead give away..

i think the easiest way after tying to decipher your posts is to pass back
the SQLDataReader then I dont have to deciper :)

thanks

"Martin#" <Ma****@discuss ions.microsoft. comwrote in message
news:8B******** *************** ***********@mic rosoft.com...
>
"M K" wrote:
>I have 2 classes. One where the form resides and I created another one
for
all the database stuff.

after i get data from the db i want to be able to update the form. I
have
the namespace of where the form code is but how do i get to the controls
themselves.

newbie in the class world.. still trying to figure it all out :)

Thanks for any help...

The management class needs to have a reference to the Form!
As the management class is supposed to be only once in memory, I would
make
a singelton out of it. This provides a static method which returns the
instance of the class.
Once the Form has the reference to the management class it could pass
their
own reference to the manager over an property
management class code:
private Form1 _myform;
public Form1 MyForm
{
get
{
return _myform;
}
set
{
if(value!=_myfo rm)
{
_myform = value;
}
}
}

Over this reference the managementclass cann then set public Properties or
call public methods with aproprtiat parameter, to modify the GUI.

If you are running the management class in an seperate thread from the GUI
you have to Invoke those methods.

Hope it helps,

All the best,

Martin

Jul 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
12108
by: Jim Heavey | last post by:
Hello, I have created a form which I intend to use a a dialog box. It has a few controls on that form and I changed the properties of those controls to "public" with the idea that I could access those controls from the "calling form", but I am unable to access/see those controls. Why? Here are portions of my code Here I am substantiating the new form and trying to set values for the controls on that form...
1
3142
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created elements and would like to seek a solution for this. I had looked through several articles for accessing programatically-created dynamic elements such as: 1)
6
2255
by: arvee | last post by:
Is there a way to access controls (and their properties) in a user control? The Web Form Designer marks controls as 'Protected' which makes them inaccessable from the host form. If I mark them as Public, I can access them, but the next time the controls are manipulated in the design mode, they are converted back to Protected. Is there an obvious/easy way around this? Thanks.
3
1346
by: Tim Fitzgerald | last post by:
Hello all, I have no problem accessing another form in my app.. however, when I try to access a ListView on a different form, I come up empty... Basically, Dim pForm As New frmMain Dim iCount As Integer iCount = pForm.lvJobList.Items.Count
4
3643
by: raj_genius | last post by:
I hav two queries, whc are as follows: FIRSTLY: is it possible to access the controls(by name) of a parent form(MDI) from its child forms??if yes then how??plzz provide a coded example in VB if possible.. for example..i hav a menu in the parent form named "Administrator" whic has an item "mnuLogIn"..now when i click on login..another child form named "frmLogIn" is displayed..what i want to happen is this: when login form(frmLogIn) is...
0
1658
by: aakash | last post by:
Hello Guys I am upsizing ms access project to give it a ms sql connectivity I am having problem in accessing form control values in ms sql function CREATE FUNCTION "ReportList DateRange"() RETURNS TABLE AS Begin RETURN
3
10525
by: judy.j.miller | last post by:
Does anyone know why i can't access a form element value using dot notation in firefox, when i'm in a function. Works ok in the body. I'm trying to do this: var FarTemp = faren.temp.value; I can get at the value using the array method, the getelements by id method, and the bracket-with-the-element-name in it method. But the dot notation doesn't work, in firefox, in the function (which i have in the head).
8
2184
by: colmkav | last post by:
Hi, could someone tell me how I can check whether a database is open by name eg something like db("mydbname")
9
1918
by: JohnR | last post by:
I have the name of a control in a string variable and I want to change one of the controls properties. Right now I recursively scan all the controls on the form until I get one whose name matches the name in my string variable, then I know I have the correct control and can proceed to change the property. However all that searching seems like overkill. Does anyone know of a way to directly access the control if it's name is in a string...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9196
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3859
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.