473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

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 2193
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!=_myform)
{
_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****@discussions.microsoft.comwrote in message
news:8B**********************************@microsof t.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!=_myform)
{
_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
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...
1
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...
6
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...
3
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...
4
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...
0
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"() ...
3
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...
8
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
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.