Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. a query

a query

Scheduled Pinned Locked Moved C#
databasehelpquestion
14 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nekshan
    wrote on last edited by
    #1

    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.

    P C V V C 6 Replies Last reply
    0
    • N Nekshan

      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.

      P Offline
      P Offline
      PandemoniumPasha
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • N Nekshan

        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.

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        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 )

        V 1 Reply Last reply
        0
        • N Nekshan

          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.

          V Offline
          V Offline
          virendra patel
          wrote on last edited by
          #4

          ' define public int n 'on top of page in form1

          V 1 Reply Last reply
          0
          • N Nekshan

            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.

            V Offline
            V Offline
            V 0
            wrote on last edited by
            #5

            you can write a property. public DateTime returnN{ get{ return n; } } if your object is still valid, you can get the value by doing datetime 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.

            1 Reply Last reply
            0
            • V virendra patel

              ' define public int n 'on top of page in form1

              V Offline
              V Offline
              V 0
              wrote on last edited by
              #6

              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.

              C 1 Reply Last reply
              0
              • C Christian Graus

                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 )

                V Offline
                V Offline
                V 0
                wrote on last edited by
                #7

                :omg: why a delegate? why not a property?

                V. I found a living worth working for, but haven't found work worth living for.

                C C 2 Replies Last reply
                0
                • N Nekshan

                  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.

                  C Offline
                  C Offline
                  Colin Angus Mackay
                  wrote on last edited by
                  #8

                  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

                  N 1 Reply Last reply
                  0
                  • V V 0

                    :omg: why a delegate? why not a property?

                    V. I found a living worth working for, but haven't found work worth living for.

                    C Offline
                    C Offline
                    Colin Angus Mackay
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    • N Nekshan

                      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.

                      G Offline
                      G Offline
                      Guffa
                      wrote on last edited by
                      #10

                      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;

                      1 Reply Last reply
                      0
                      • V V 0

                        :omg: why a delegate? why not a property?

                        V. I found a living worth working for, but haven't found work worth living for.

                        C Offline
                        C Offline
                        Christian Graus
                        wrote on last edited by
                        #11

                        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 )

                        1 Reply Last reply
                        0
                        • V V 0

                          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.

                          C Offline
                          C Offline
                          Christian Graus
                          wrote on last edited by
                          #12

                          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 )

                          V 1 Reply Last reply
                          0
                          • C Christian Graus

                            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 )

                            V Offline
                            V Offline
                            V 0
                            wrote on last edited by
                            #13

                            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

                            1 Reply Last reply
                            0
                            • C Colin Angus Mackay

                              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

                              N Offline
                              N Offline
                              Nekshan
                              wrote on last edited by
                              #14

                              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

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups