dim test as new form1

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Maarten

    dim test as new form1

    hi all,

    i have a settingform(for m4)

    this form opens from an mdi parent form1
    what i want do do is, when i make change in form4 (adjust settings), then a
    listview in the mdi parent form1 refreches, this is what i did.

    Public Class Form4

    Inherits System.Windows. Forms.Form

    Dim windowmain As New Form1()

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button1.Click

    Next inti

    otherwindow.lis tsetup()

    Me.close

    End Sub

    now the problem is, when i try to open form4 i get an error by all of the
    components of

    " Object reference not set to an instance of an object."
    form1, i think becouse i declare the form as a new form1.

    what can i do to comunicate with form1



    Regards,

    Maarten




  • Cor Ligthert

    #2
    Re: dim test as new form1

    Maarten,

    The simple way is in my opinion that you can work forever from your
    me.parentform.m dichildren collection

    Something as this in your form4 which is very much changed text in this
    message so watch typos
    \\\
    For Each frm As Form In Me.ParentForm.M diChildren
    If frm.Name = "frm1" Then
    DirectCast(frm, form1).Whatever = text.Text
    Exit Sub
    End If
    Next
    ///
    I hope this helps?

    Cor

    "Maarten" <gurkjaan@hotma il.com>>
    hi all,[color=blue]
    >
    > i have a settingform(for m4)
    >
    > this form opens from an mdi parent form1
    > what i want do do is, when i make change in form4 (adjust settings), then
    > a listview in the mdi parent form1 refreches, this is what i did.
    >
    > Public Class Form4
    >
    > Inherits System.Windows. Forms.Form
    >
    > Dim windowmain As New Form1()
    >
    > Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
    > System.EventArg s) Handles Button1.Click
    >
    > Next inti
    >
    > otherwindow.lis tsetup()
    >
    > Me.close
    >
    > End Sub
    >
    > now the problem is, when i try to open form4 i get an error by all of the
    > components of
    >
    > " Object reference not set to an instance of an object."
    > form1, i think becouse i declare the form as a new form1.
    >
    > what can i do to comunicate with form1
    >
    >
    >
    > Regards,
    >
    > Maarten
    >
    >
    >
    >[/color]


    Comment

    • Maarten

      #3
      Re: dim test as new form1

      thanks for the reply

      but i get an error ( syntax error) by "AS" in For Each frm As Form In
      Me.ParentForm.M diChildren.

      but i was thinking that it meightbe more simple, if i get the data from the
      childform when the parrentform is focussed?

      but how wil i do this?
      anny suggestions are welcome.

      kind regards Maarten.



      "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
      news:%23uF30k$6 EHA.2568@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      > Maarten,
      >
      > The simple way is in my opinion that you can work forever from your
      > me.parentform.m dichildren collection
      >
      > Something as this in your form4 which is very much changed text in this
      > message so watch typos
      > \\\
      > For Each frm As Form In Me.ParentForm.M diChildren
      > If frm.Name = "frm1" Then
      > DirectCast(frm, form1).Whatever = text.Text
      > Exit Sub
      > End If
      > Next
      > ///
      > I hope this helps?
      >
      > Cor
      >
      > "Maarten" <gurkjaan@hotma il.com>>
      > hi all,[color=green]
      >>
      >> i have a settingform(for m4)
      >>
      >> this form opens from an mdi parent form1
      >> what i want do do is, when i make change in form4 (adjust settings), then
      >> a listview in the mdi parent form1 refreches, this is what i did.
      >>
      >> Public Class Form4
      >>
      >> Inherits System.Windows. Forms.Form
      >>
      >> Dim windowmain As New Form1()
      >>
      >> Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
      >> System.EventArg s) Handles Button1.Click
      >>
      >> Next inti
      >>
      >> otherwindow.lis tsetup()
      >>
      >> Me.close
      >>
      >> End Sub
      >>
      >> now the problem is, when i try to open form4 i get an error by all of the
      >> components of
      >>
      >> " Object reference not set to an instance of an object."
      >> form1, i think becouse i declare the form as a new form1.
      >>
      >> what can i do to comunicate with form1
      >>
      >>
      >>
      >> Regards,
      >>
      >> Maarten
      >>
      >>
      >>
      >>[/color]
      >
      >[/color]


      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: dim test as new form1

        "Maarten" <gurkjaan@hotma il.com> schrieb:[color=blue]
        > but i get an error ( syntax error) by "AS" in For Each frm As Form In
        > Me.ParentForm.M diChildren.[/color]

        I assume you are using VB.NET 2002:

        \\\
        Dim f As Form
        For Each f In Me.MdiChildren
        ...
        Next f
        ///

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


        Comment

        • Maarten

          #5
          Re: dim test as new form1

          hi,
          thanks to reply my quesion.

          but it won't work

          \\\
          Dim f As Form
          For Each f In Me.MdiChildren
          ...
          Next f
          ///

          form4 is a childform and has no children
          so i think "For Each f In Me.MdiChildren" can't work.(i've writen this code
          in form4)

          i want to refresh a listview in the parentform(form 1) when i press a button
          in in the childform.(form 4)

          regards,
          Maarten





          "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
          news:uwiNo1A7EH A.2700@TK2MSFTN GP14.phx.gbl...[color=blue]
          > "Maarten" <gurkjaan@hotma il.com> schrieb:[color=green]
          >> but i get an error ( syntax error) by "AS" in For Each frm As Form In
          >> Me.ParentForm.M diChildren.[/color]
          >
          > I assume you are using VB.NET 2002:
          >
          > \\\
          > Dim f As Form
          > For Each f In Me.MdiChildren
          > ...
          > Next f
          > ///
          >
          > --
          > M S Herfried K. Wagner
          > M V P <URL:http://dotnet.mvps.org/>
          > V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
          >[/color]


          Comment

          • Cor Ligthert

            #6
            Re: dim test as new form1

            Maarten,

            Are you using VBNet 2002
            Than my sample becomes

            dim frm as Form
            \\\
            For Each frm In Me.ParentForm.M diChildren
            If frm.Name = "frm1" Then
            DirectCast(frm, form1).Whatever = text.Text
            Exit Sub
            End If
            Next
            ///

            Cor


            Cor


            Comment

            • Herfried K. Wagner [MVP]

              #7
              Re: dim test as new form1

              "Maarten" <gurkjaan@hotma il.com> schrieb:[color=blue]
              > i want to refresh a listview in the parentform(form 1) when i press a
              > button in in the childform.(form 4)[/color]

              \\\
              DirectCast(Me.M diParent, MainForm).Butto n1.Text = "Hello World!"
              ///

              --
              M S Herfried K. Wagner
              M V P <URL:http://dotnet.mvps.org/>
              V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


              Comment

              • Cor Ligthert

                #8
                Re: dim test as new form1

                Maarten,

                I think at least I am confused by this text of you
                \\\
                this form opens from an mdi parent form1
                what i want do do is, when i make change in form4 (adjust settings), then a
                listview in the mdi parent form1 refreches, this is what i did.
                ///

                A listview on a MDI parent? How did you do that, is this using panels or
                something? A kind of Delphi way form.

                Cor

                "Maarten" <gurkjaan@hotma il.com>
                [color=blue]
                > hi,
                > thanks to reply my quesion.
                >
                > but it won't work
                >
                > \\\
                > Dim f As Form
                > For Each f In Me.MdiChildren
                > ...
                > Next f
                > ///
                >
                > form4 is a childform and has no children
                > so i think "For Each f In Me.MdiChildren" can't work.(i've writen this
                > code in form4)
                >
                > i want to refresh a listview in the parentform(form 1) when i press a
                > button in in the childform.(form 4)
                >
                > regards,
                > Maarten
                >
                >
                >
                >
                >
                > "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
                > news:uwiNo1A7EH A.2700@TK2MSFTN GP14.phx.gbl...[color=green]
                >> "Maarten" <gurkjaan@hotma il.com> schrieb:[color=darkred]
                >>> but i get an error ( syntax error) by "AS" in For Each frm As Form In
                >>> Me.ParentForm.M diChildren.[/color]
                >>
                >> I assume you are using VB.NET 2002:
                >>
                >> \\\
                >> Dim f As Form
                >> For Each f In Me.MdiChildren
                >> ...
                >> Next f
                >> ///
                >>
                >> --
                >> M S Herfried K. Wagner
                >> M V P <URL:http://dotnet.mvps.org/>
                >> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
                >>[/color]
                >
                >[/color]


                Comment

                • Maarten

                  #9
                  Re: dim test as new form1

                  indeed a listview on a parrent form in a pannel docked left.

                  the interface of my program looks like visual studio.net
                  there are some tools in that listview

                  regards,
                  Maarten

                  "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
                  news:upR3jmC7EH A.3908@TK2MSFTN GP12.phx.gbl...[color=blue]
                  > Maarten,
                  >
                  > I think at least I am confused by this text of you
                  > \\\
                  > this form opens from an mdi parent form1
                  > what i want do do is, when i make change in form4 (adjust settings), then
                  > a
                  > listview in the mdi parent form1 refreches, this is what i did.
                  > ///
                  >
                  > A listview on a MDI parent? How did you do that, is this using panels or
                  > something? A kind of Delphi way form.
                  >
                  > Cor
                  >
                  > "Maarten" <gurkjaan@hotma il.com>
                  >[color=green]
                  >> hi,
                  >> thanks to reply my quesion.
                  >>
                  >> but it won't work
                  >>
                  >> \\\
                  >> Dim f As Form
                  >> For Each f In Me.MdiChildren
                  >> ...
                  >> Next f
                  >> ///
                  >>
                  >> form4 is a childform and has no children
                  >> so i think "For Each f In Me.MdiChildren" can't work.(i've writen this
                  >> code in form4)
                  >>
                  >> i want to refresh a listview in the parentform(form 1) when i press a
                  >> button in in the childform.(form 4)
                  >>
                  >> regards,
                  >> Maarten
                  >>
                  >>
                  >>
                  >>
                  >>
                  >> "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
                  >> news:uwiNo1A7EH A.2700@TK2MSFTN GP14.phx.gbl...[color=darkred]
                  >>> "Maarten" <gurkjaan@hotma il.com> schrieb:
                  >>>> but i get an error ( syntax error) by "AS" in For Each frm As Form In
                  >>>> Me.ParentForm.M diChildren.
                  >>>
                  >>> I assume you are using VB.NET 2002:
                  >>>
                  >>> \\\
                  >>> Dim f As Form
                  >>> For Each f In Me.MdiChildren
                  >>> ...
                  >>> Next f
                  >>> ///
                  >>>
                  >>> --
                  >>> M S Herfried K. Wagner
                  >>> M V P <URL:http://dotnet.mvps.org/>
                  >>> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
                  >>>[/color]
                  >>
                  >>[/color]
                  >
                  >[/color]


                  Comment

                  • Maarten

                    #10
                    Re: dim test as new form1

                    yes i use vb.net 2002

                    regards,
                    Maarten

                    "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
                    news:upR3jmC7EH A.3908@TK2MSFTN GP12.phx.gbl...[color=blue]
                    > Maarten,
                    >
                    > I think at least I am confused by this text of you
                    > \\\
                    > this form opens from an mdi parent form1
                    > what i want do do is, when i make change in form4 (adjust settings), then
                    > a
                    > listview in the mdi parent form1 refreches, this is what i did.
                    > ///
                    >
                    > A listview on a MDI parent? How did you do that, is this using panels or
                    > something? A kind of Delphi way form.
                    >
                    > Cor
                    >
                    > "Maarten" <gurkjaan@hotma il.com>
                    >[color=green]
                    >> hi,
                    >> thanks to reply my quesion.
                    >>
                    >> but it won't work
                    >>
                    >> \\\
                    >> Dim f As Form
                    >> For Each f In Me.MdiChildren
                    >> ...
                    >> Next f
                    >> ///
                    >>
                    >> form4 is a childform and has no children
                    >> so i think "For Each f In Me.MdiChildren" can't work.(i've writen this
                    >> code in form4)
                    >>
                    >> i want to refresh a listview in the parentform(form 1) when i press a
                    >> button in in the childform.(form 4)
                    >>
                    >> regards,
                    >> Maarten
                    >>
                    >>
                    >>
                    >>
                    >>
                    >> "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
                    >> news:uwiNo1A7EH A.2700@TK2MSFTN GP14.phx.gbl...[color=darkred]
                    >>> "Maarten" <gurkjaan@hotma il.com> schrieb:
                    >>>> but i get an error ( syntax error) by "AS" in For Each frm As Form In
                    >>>> Me.ParentForm.M diChildren.
                    >>>
                    >>> I assume you are using VB.NET 2002:
                    >>>
                    >>> \\\
                    >>> Dim f As Form
                    >>> For Each f In Me.MdiChildren
                    >>> ...
                    >>> Next f
                    >>> ///
                    >>>
                    >>> --
                    >>> M S Herfried K. Wagner
                    >>> M V P <URL:http://dotnet.mvps.org/>
                    >>> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
                    >>>[/color]
                    >>
                    >>[/color]
                    >
                    >[/color]


                    Comment

                    • Larry Serflaten

                      #11
                      Re: dim test as new form1


                      "Maarten" <gurkjaan@hotma il.com> wrote
                      [color=blue]
                      > i want to refresh a listview in the parentform(form 1) when i press a button
                      > in in the childform.(form 4)[/color]

                      Take a step back and look at what you have. You basically have some data
                      (your settings) and you want to show the current state of it in multiple forms.
                      What that means is that no matter how many other forms are allowed to edit
                      or change the data, everyone else who is displaying the data needs to be notified
                      of the change (so they can update their own 'view').

                      What that amounts to is that you create a class that represents your data
                      and that can raise events (when the data changes). Any forms that display
                      your data would get their data from that data class, and they would subscribe
                      to the events of that class to be notified of any changes. You'd give it properties
                      to get access to the raw settings, and you'd raise events when the settings change.
                      You might even implement an interface or two (like IList) to make using the data
                      a bit easier, but that is not required.

                      In the 'pattern' culture, you are looking for an Observer pattern, perhaps using
                      that term in the search engines will help you find simple .Net examples.

                      HTH
                      LFS

                      Comment

                      • Cor Ligthert

                        #12
                        Re: dim test as new form1

                        Clear,

                        Than the last sample from Herfried would fit in my opinion.

                        Cor


                        Comment

                        • Maarten

                          #13
                          Re: dim test as new form1

                          What i do now, is store the data in in a couple of arrays, this is the
                          datastorage where all my forms get their data.

                          I think i undertand what you mean with youre last reply, i downloaded an
                          example code.
                          but i dont think this wil solve my problem.

                          I manage to store the data and get it when the program starts, or when i
                          press a button in the mdi form or when i dragover the listview and more like
                          this.
                          but i just can't figure out how to let in this case a listview(in the
                          parrentform) get's its data by refreshing when i press a button in another
                          form (a childform) .

                          i was thinking to set a timer on the refresh property of the listview, but i
                          don't think this is a propper way to get up to date with data changes in my
                          program, there must be a more simple way. but how.

                          the last code you gave me won't work, i get an error "Object reference not
                          set to an instance of an object."

                          thanks for the reply's

                          kind regards Maarten.




                          "Larry Serflaten" <serflaten@usin ternet.com> wrote in message
                          news:ehWRbBD7EH A.2180@TK2MSFTN GP10.phx.gbl...[color=blue]
                          >
                          > "Maarten" <gurkjaan@hotma il.com> wrote
                          >[color=green]
                          >> i want to refresh a listview in the parentform(form 1) when i press a
                          >> button
                          >> in in the childform.(form 4)[/color]
                          >
                          > Take a step back and look at what you have. You basically have some data
                          > (your settings) and you want to show the current state of it in multiple
                          > forms.
                          > What that means is that no matter how many other forms are allowed to edit
                          > or change the data, everyone else who is displaying the data needs to be
                          > notified
                          > of the change (so they can update their own 'view').
                          >
                          > What that amounts to is that you create a class that represents your data
                          > and that can raise events (when the data changes). Any forms that display
                          > your data would get their data from that data class, and they would
                          > subscribe
                          > to the events of that class to be notified of any changes. You'd give it
                          > properties
                          > to get access to the raw settings, and you'd raise events when the
                          > settings change.
                          > You might even implement an interface or two (like IList) to make using
                          > the data
                          > a bit easier, but that is not required.
                          >
                          > In the 'pattern' culture, you are looking for an Observer pattern, perhaps
                          > using
                          > that term in the search engines will help you find simple .Net examples.
                          >
                          > HTH
                          > LFS
                          >[/color]


                          Comment

                          • Cor Ligthert

                            #14
                            Re: dim test as new form1

                            Maarten,

                            I did not see that you asked this one
                            \\\
                            me.mdiparent.sh ow
                            ///
                            Not tested by the way

                            Cor

                            "Maarten" <gurkjaan@hotma il.com>[color=blue]
                            > What i do now, is store the data in in a couple of arrays, this is the
                            > datastorage where all my forms get their data.
                            >
                            > I think i undertand what you mean with youre last reply, i downloaded an
                            > example code.
                            > but i dont think this wil solve my problem.
                            >
                            > I manage to store the data and get it when the program starts, or when i
                            > press a button in the mdi form or when i dragover the listview and more
                            > like this.
                            > but i just can't figure out how to let in this case a listview(in the
                            > parrentform) get's its data by refreshing when i press a button in another
                            > form (a childform) .
                            >
                            > i was thinking to set a timer on the refresh property of the listview, but
                            > i don't think this is a propper way to get up to date with data changes in
                            > my program, there must be a more simple way. but how.
                            >
                            > the last code you gave me won't work, i get an error "Object reference not
                            > set to an instance of an object."
                            >
                            > thanks for the reply's
                            >
                            > kind regards Maarten.
                            >
                            >
                            >
                            >
                            > "Larry Serflaten" <serflaten@usin ternet.com> wrote in message
                            > news:ehWRbBD7EH A.2180@TK2MSFTN GP10.phx.gbl...[color=green]
                            >>
                            >> "Maarten" <gurkjaan@hotma il.com> wrote
                            >>[color=darkred]
                            >>> i want to refresh a listview in the parentform(form 1) when i press a
                            >>> button
                            >>> in in the childform.(form 4)[/color]
                            >>
                            >> Take a step back and look at what you have. You basically have some data
                            >> (your settings) and you want to show the current state of it in multiple
                            >> forms.
                            >> What that means is that no matter how many other forms are allowed to
                            >> edit
                            >> or change the data, everyone else who is displaying the data needs to be
                            >> notified
                            >> of the change (so they can update their own 'view').
                            >>
                            >> What that amounts to is that you create a class that represents your data
                            >> and that can raise events (when the data changes). Any forms that
                            >> display
                            >> your data would get their data from that data class, and they would
                            >> subscribe
                            >> to the events of that class to be notified of any changes. You'd give it
                            >> properties
                            >> to get access to the raw settings, and you'd raise events when the
                            >> settings change.
                            >> You might even implement an interface or two (like IList) to make using
                            >> the data
                            >> a bit easier, but that is not required.
                            >>
                            >> In the 'pattern' culture, you are looking for an Observer pattern,
                            >> perhaps using
                            >> that term in the search engines will help you find simple .Net examples.
                            >>
                            >> HTH
                            >> LFS
                            >>[/color]
                            >
                            >[/color]


                            Comment

                            • Maarten

                              #15
                              Re: dim test as new form1


                              i still get an error

                              "Object reference not set to an instance of an object."

                              Maarten.


                              "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
                              news:u0bWPbE7EH A.1452@TK2MSFTN GP11.phx.gbl...[color=blue]
                              > Maarten,
                              >
                              > I did not see that you asked this one
                              > \\\
                              > me.mdiparent.sh ow
                              > ///
                              > Not tested by the way
                              >
                              > Cor
                              >
                              > "Maarten" <gurkjaan@hotma il.com>[color=green]
                              >> What i do now, is store the data in in a couple of arrays, this is the
                              >> datastorage where all my forms get their data.
                              >>
                              >> I think i undertand what you mean with youre last reply, i downloaded an
                              >> example code.
                              >> but i dont think this wil solve my problem.
                              >>
                              >> I manage to store the data and get it when the program starts, or when i
                              >> press a button in the mdi form or when i dragover the listview and more
                              >> like this.
                              >> but i just can't figure out how to let in this case a listview(in the
                              >> parrentform) get's its data by refreshing when i press a button in
                              >> another form (a childform) .
                              >>
                              >> i was thinking to set a timer on the refresh property of the listview,
                              >> but i don't think this is a propper way to get up to date with data
                              >> changes in my program, there must be a more simple way. but how.
                              >>
                              >> the last code you gave me won't work, i get an error "Object reference
                              >> not set to an instance of an object."
                              >>
                              >> thanks for the reply's
                              >>
                              >> kind regards Maarten.
                              >>
                              >>
                              >>
                              >>
                              >> "Larry Serflaten" <serflaten@usin ternet.com> wrote in message
                              >> news:ehWRbBD7EH A.2180@TK2MSFTN GP10.phx.gbl...[color=darkred]
                              >>>
                              >>> "Maarten" <gurkjaan@hotma il.com> wrote
                              >>>
                              >>>> i want to refresh a listview in the parentform(form 1) when i press a
                              >>>> button
                              >>>> in in the childform.(form 4)
                              >>>
                              >>> Take a step back and look at what you have. You basically have some
                              >>> data
                              >>> (your settings) and you want to show the current state of it in multiple
                              >>> forms.
                              >>> What that means is that no matter how many other forms are allowed to
                              >>> edit
                              >>> or change the data, everyone else who is displaying the data needs to be
                              >>> notified
                              >>> of the change (so they can update their own 'view').
                              >>>
                              >>> What that amounts to is that you create a class that represents your
                              >>> data
                              >>> and that can raise events (when the data changes). Any forms that
                              >>> display
                              >>> your data would get their data from that data class, and they would
                              >>> subscribe
                              >>> to the events of that class to be notified of any changes. You'd give
                              >>> it properties
                              >>> to get access to the raw settings, and you'd raise events when the
                              >>> settings change.
                              >>> You might even implement an interface or two (like IList) to make using
                              >>> the data
                              >>> a bit easier, but that is not required.
                              >>>
                              >>> In the 'pattern' culture, you are looking for an Observer pattern,
                              >>> perhaps using
                              >>> that term in the search engines will help you find simple .Net examples.
                              >>>
                              >>> HTH
                              >>> LFS
                              >>>[/color]
                              >>
                              >>[/color]
                              >
                              >[/color]


                              Comment

                              Working...