a query
-
datetime n = form1.n; -- Not Working : error on 'n'. 'System.Windows.Forms.Form' does not contain a definition for 'n'. just have to define a variable 'int n' in form1, n try to access it in form2. how? :-( nekshan.
if you only need to pass the value of the variable 'n' to form2 then just pass the variable as an argument of the form2 constructor eg. Form2 frm= new Form2(n); if that value need to be modified and updated in form1 you could declare it as static eg. public static int n; and modify it in form2 as: Form1.n=5; hope this helps.
-
datetime n = form1.n; -- Not Working : error on 'n'. 'System.Windows.Forms.Form' does not contain a definition for 'n'. just have to define a variable 'int n' in form1, n try to access it in form2. how? :-( nekshan.
The obvious way is to pass it in, as someone said. The drawback of using statics is, it means you can only have one instance of that form. The best way to communicate from form2 back to form1 is a delegate.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
datetime n = form1.n; -- Not Working : error on 'n'. 'System.Windows.Forms.Form' does not contain a definition for 'n'. just have to define a variable 'int n' in form1, n try to access it in form2. how? :-( nekshan.
' define public int n 'on top of page in form1
-
datetime n = form1.n; -- Not Working : error on 'n'. 'System.Windows.Forms.Form' does not contain a definition for 'n'. just have to define a variable 'int n' in form1, n try to access it in form2. how? :-( nekshan.
you can write a property.
public DateTime returnN{ get{ return n; } }
if your object is still valid, you can get the value by doingdatetime n = form1.returnN;
A static variable is not suitable for this and neither is making 'n' public in Form1. good luck :-)V. I found a living worth working for, but haven't found work worth living for.
-
' define public int n 'on top of page in form1
-
The obvious way is to pass it in, as someone said. The drawback of using statics is, it means you can only have one instance of that form. The best way to communicate from form2 back to form1 is a delegate.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
datetime n = form1.n; -- Not Working : error on 'n'. 'System.Windows.Forms.Form' does not contain a definition for 'n'. just have to define a variable 'int n' in form1, n try to access it in form2. how? :-( nekshan.
You could read this article on passing values between forms[^]
Upcoming events: * Glasgow: Geek Dinner (5th March) * Edinburgh: Web Security Conference Day for Windows Developers (12th April) My: Website | Blog | Photos
-
:omg: why a delegate? why not a property?
V. I found a living worth working for, but haven't found work worth living for.
V. wrote:
why a delegate? why not a property?
Loose coupling - So the forms don't have to know about each other.
Upcoming events: * Glasgow: Geek Dinner (5th March) * Edinburgh: Web Security Conference Day for Windows Developers (12th April) My: Website | Blog | Photos
-
datetime n = form1.n; -- Not Working : error on 'n'. 'System.Windows.Forms.Form' does not contain a definition for 'n'. just have to define a variable 'int n' in form1, n try to access it in form2. how? :-( nekshan.
I already explained exactly why you are unable to access the member, in your previous thread about the same thing. If you can't keep your question in one thread, at least read the replies you get in the threads. :(
--- single minded; short sighted; long gone;
-
:omg: why a delegate? why not a property?
V. I found a living worth working for, but haven't found work worth living for.
As well as loose coupling, a delegate will allow a value to be sent between forms that are both active ( if form2 is modeless and form1 needs to update itself right away )
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
bad idea, it's against incapsulation rules. You should use a property for that :-D
V. I found a living worth working for, but haven't found work worth living for.
And make the property read only, or you break encapsulation just the same
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
And make the property read only, or you break encapsulation just the same
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
I tend to disagree. Suppose I have a variable
distance
(integer) A distance can never be smaller then 0. If I make my variable public, you can set it to what integer you like even < 0. With a property you could build in a check.set{ if(value >= 0){ distance = value; } else{ distance = 0; } }
V.
Stop smoking so you can: Enjoy longer the money you save. Moviereview Archive -
You could read this article on passing values between forms[^]
Upcoming events: * Glasgow: Geek Dinner (5th March) * Edinburgh: Web Security Conference Day for Windows Developers (12th April) My: Website | Blog | Photos
hi!! i had been refering to article 'passing values betn forms'. I tried from it, but still i cant pass my variable from form1 to form2. I m getting error on passing my variable to the other form's variable. i have used the object approach from that article : http://www.codeproject.com/useritems/pass\_data\_between\_forms.asp Objects of forms are created properly. This i have written in form1 : p = ((form1)log).n; // log is object of form2. //variable 'n' i have to bring from form2,which contains a date from query fired. but i m getting error : 'Object reference not set to an instance of an object.' It would be v.nice if u could help on it. Thanx. -- modified at 6:20 Wednesday 21st February, 2007