473,405 Members | 2,261 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,405 software developers and data experts.

setting controls/values from one form to another

Hi there,

Just doing a little testing and if i set a control or variable , say on
form2 (DataGrid1), then i type:

Form1 f1 = new Form1();
f1.DataGrid1.datasource = ......
f1.Show()
---------------------------------

(in Form2) i set:

private DataGrid DataGrid1; -->public DataGrid DataGrid1;

but in order to access the datagrid from this form, i just changed it from
Private to Public. Is it okay to do it this way in order to access controls
on other forms?
Does anyone have a reason why not to do it like this:

thanks,
Paul
Mar 20 '07 #1
2 1056
"Milsnips" <mi******@hotmail.comwrote in message
news:eQ**************@TK2MSFTNGP06.phx.gbl...
[...]
(in Form2) i set:

private DataGrid DataGrid1; -->public DataGrid DataGrid1;

but in order to access the datagrid from this form, i just changed it from
Private to Public. Is it okay to do it this way in order to access
controls on other forms?
This will work, but it is a best practice to publish a property while
keeping the field itself private:

private DataGrid DataGrid1;
public DataGrid TheDataGrid
{
get { return DataGrid1; }
}

Notice that this is a read-only property. It still allows the DataSource
or other properties of the Grid to be modified from outside the form, but
will prevent the Grid itself to be replaced from the outside.

Mar 20 '07 #2
Ok thanks, i'l give that a try.

regards,
Paul

"Alberto Poblacion" <ea******************************@poblacion.orgwro te
in message news:e%****************@TK2MSFTNGP03.phx.gbl...
"Milsnips" <mi******@hotmail.comwrote in message
news:eQ**************@TK2MSFTNGP06.phx.gbl...
>[...]
(in Form2) i set:

private DataGrid DataGrid1; -->public DataGrid DataGrid1;

but in order to access the datagrid from this form, i just changed it
from Private to Public. Is it okay to do it this way in order to access
controls on other forms?

This will work, but it is a best practice to publish a property while
keeping the field itself private:

private DataGrid DataGrid1;
public DataGrid TheDataGrid
{
get { return DataGrid1; }
}

Notice that this is a read-only property. It still allows the
DataSource or other properties of the Grid to be modified from outside the
form, but will prevent the Grid itself to be replaced from the outside.

Mar 20 '07 #3

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

Similar topics

7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
2
by: John Hargrove | last post by:
I'm having trouble setting decimal place values in the results field of a sample management database I'm building for an environmental testing laboratory. The degree of sensitivity varies among...
7
by: charliewest | last post by:
Using .Net CF, i have created a 2 dimension ArrayList, and "binded" this list to a ComboBox control using the "DataSource" property. I have set the DisplaySource and ValueMember properties as well....
10
by: Sacha Korell | last post by:
I'm trying to load a drop-down list with all DropDownList control names from another page. How would I be able to find those DropDownList controls? The FindControl method will only find a...
22
by: Mr Newbie | last post by:
I was thinking about developing a workflow application yesterday and was musing over the different approaches than one could take in restricting specific actions on a ticket( Form ) at any said...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
5
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button....
0
by: anandv81 | last post by:
Hi, I encountered a strange problem while working on an application, the problem goes like this. I am generating a few textboxes at runtime at the server side and added to a placeholder, a...
3
by: Mark Rae | last post by:
Hi, Just a general quickie on setting properties of user controls from the parent form. Let's say I have a user control called note.ascx which displays a datagrid. That datagrid is populated...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.