Update LIST<T> from a different form

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

    #1

    Update LIST<T> from a different form

    Hi,

    I wish to update the LIST<T> created in PARENT FORM from the CHILD FORM.
    Currently I have declared the LIST<Role> as public in my parent form. What
    can I do to update the <LIST>?

    Thanks


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Update LIST&lt;T&gt; from a different form

    Vivek,

    Why not pass the List<T> to the child form when you create it from the
    parent? You can pass it through a constructor, through a property, public
    field, or method.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Vivek" <viveks@xtra.co .nz> wrote in message
    news:ubc1gxyCGH A.3708@TK2MSFTN GP12.phx.gbl...[color=blue]
    > Hi,
    >
    > I wish to update the LIST<T> created in PARENT FORM from the CHILD FORM.
    > Currently I have declared the LIST<Role> as public in my parent form.
    > What can I do to update the <LIST>?
    >
    > Thanks
    >[/color]


    Comment

    • Vivek

      #3
      Re: Update LIST&lt;T&gt; from a different form

      It sure did. I'll have to find out how to pass the list to the child form.
      can you please mention if you know an efficient way.

      Thanks


      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
      message news:e9K7XzyCGH A.4016@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Vivek,
      >
      > Why not pass the List<T> to the child form when you create it from the
      > parent? You can pass it through a constructor, through a property, public
      > field, or method.
      >
      > Hope this helps.
      >
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - mvp@spam.guard. caspershouse.co m
      >
      > "Vivek" <viveks@xtra.co .nz> wrote in message
      > news:ubc1gxyCGH A.3708@TK2MSFTN GP12.phx.gbl...[color=green]
      >> Hi,
      >>
      >> I wish to update the LIST<T> created in PARENT FORM from the CHILD FORM.
      >> Currently I have declared the LIST<Role> as public in my parent form.
      >> What can I do to update the <LIST>?
      >>
      >> Thanks
      >>[/color]
      >
      >[/color]


      Comment

      • Joanna Carter [TeamB]

        #4
        Re: Update LIST&lt;T&gt; from a different form

        "Vivek" <viveks@xtra.co .nz> a écrit dans le message de news:
        ubc1gxyCGHA.370 8@TK2MSFTNGP12. phx.gbl...

        | I wish to update the LIST<T> created in PARENT FORM from the CHILD FORM.
        | Currently I have declared the LIST<Role> as public in my parent form.
        What
        | can I do to update the <LIST>?

        I already answered this, here is my reply from the other thread :

        ////////////////////////////
        If you want to allow full interaction with a list from controls like
        DataGridView, etc, then you should create your own generic list class that
        implements a couple of interfaces :

        GenericList<T> : IList<T>, IBindingList, ICancelAddNew
        {
        private IList<T> items = new List<T>;

        ...
        }

        In implementing this class you can then talk to the database from inside
        this list class, intercepting the calls that would normally go straight to a
        List<T> and adding your own code to keep the database in sync.

        Because of the interfaces implemented, data-aware list controls should
        update themselves automatically.
        ///////////////////////////:

        Joanna

        --
        Joanna Carter [TeamB]
        Consultant Software Engineer


        Comment

        • Nicholas Paldino [.NET/C# MVP]

          #5
          Re: Update LIST&lt;T&gt; from a different form

          Vivek,

          Again, why not just call a method on the child form, passing the list to
          it? It's like passing a parameter to any other method.

          --
          - Nicholas Paldino [.NET/C# MVP]
          - mvp@spam.guard. caspershouse.co m

          "Vivek" <viveks@xtra.co .nz> wrote in message
          news:uWl$N2yCGH A.4004@tk2msftn gp13.phx.gbl...[color=blue]
          > It sure did. I'll have to find out how to pass the list to the child
          > form. can you please mention if you know an efficient way.
          >
          > Thanks
          >
          >
          > "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote
          > in message news:e9K7XzyCGH A.4016@TK2MSFTN GP11.phx.gbl...[color=green]
          >> Vivek,
          >>
          >> Why not pass the List<T> to the child form when you create it from the
          >> parent? You can pass it through a constructor, through a property,
          >> public field, or method.
          >>
          >> Hope this helps.
          >>
          >>
          >> --
          >> - Nicholas Paldino [.NET/C# MVP]
          >> - mvp@spam.guard. caspershouse.co m
          >>
          >> "Vivek" <viveks@xtra.co .nz> wrote in message
          >> news:ubc1gxyCGH A.3708@TK2MSFTN GP12.phx.gbl...[color=darkred]
          >>> Hi,
          >>>
          >>> I wish to update the LIST<T> created in PARENT FORM from the CHILD FORM.
          >>> Currently I have declared the LIST<Role> as public in my parent form.
          >>> What can I do to update the <LIST>?
          >>>
          >>> Thanks
          >>>[/color]
          >>
          >>[/color]
          >
          >[/color]


          Comment

          • Vivek

            #6
            Re: Update LIST&lt;T&gt; from a different form

            I have a class ROLE with all the properties declared. I am adding the roles
            to the list
            I tried this and gave me an error
            *************** *************** *************** ********
            public RoleForm(int RoleID, List<T> lRole)

            {

            InitializeCompo nent();

            _ID = RoleID;

            }

            *************** *************** *************** *************** **

            ERROR:Error 1 The type or namespace name 'T' could not be found (are you
            missing a using directive or an assembly reference?)

            *************** *************** *************** ********

            "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
            message news:%234RSw4yC GHA.3820@TK2MSF TNGP12.phx.gbl. ..[color=blue]
            > Vivek,
            >
            > Again, why not just call a method on the child form, passing the list
            > to it? It's like passing a parameter to any other method.
            >
            > --
            > - Nicholas Paldino [.NET/C# MVP]
            > - mvp@spam.guard. caspershouse.co m
            >
            > "Vivek" <viveks@xtra.co .nz> wrote in message
            > news:uWl$N2yCGH A.4004@tk2msftn gp13.phx.gbl...[color=green]
            >> It sure did. I'll have to find out how to pass the list to the child
            >> form. can you please mention if you know an efficient way.
            >>
            >> Thanks
            >>
            >>
            >> "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote
            >> in message news:e9K7XzyCGH A.4016@TK2MSFTN GP11.phx.gbl...[color=darkred]
            >>> Vivek,
            >>>
            >>> Why not pass the List<T> to the child form when you create it from
            >>> the parent? You can pass it through a constructor, through a property,
            >>> public field, or method.
            >>>
            >>> Hope this helps.
            >>>
            >>>
            >>> --
            >>> - Nicholas Paldino [.NET/C# MVP]
            >>> - mvp@spam.guard. caspershouse.co m
            >>>
            >>> "Vivek" <viveks@xtra.co .nz> wrote in message
            >>> news:ubc1gxyCGH A.3708@TK2MSFTN GP12.phx.gbl...
            >>>> Hi,
            >>>>
            >>>> I wish to update the LIST<T> created in PARENT FORM from the CHILD
            >>>> FORM. Currently I have declared the LIST<Role> as public in my parent
            >>>> form. What can I do to update the <LIST>?
            >>>>
            >>>> Thanks
            >>>>
            >>>
            >>>[/color]
            >>
            >>[/color]
            >
            >[/color]


            Comment

            • Nicholas Paldino [.NET/C# MVP]

              #7
              Re: Update LIST&lt;T&gt; from a different form

              Vivek,

              Unless your class is Generic, you want to do this:

              public RoleForm(int RoleId, List<Role> lRole)

              By the way, you should not name your parameter lRole, but rather, Roles.
              The public naming guidelines indicate that you should do something else.

              The reason what I typed works is because when you say List<T>, if T
              isn't a type parameter, then the compiler will look for a type named T. You
              need to set the specific type for the generic parameter.


              --
              - Nicholas Paldino [.NET/C# MVP]
              - mvp@spam.guard. caspershouse.co m

              "Vivek" <viveks@xtra.co .nz> wrote in message
              news:ecR31BzCGH A.516@TK2MSFTNG P15.phx.gbl...[color=blue]
              >I have a class ROLE with all the properties declared. I am adding the roles
              >to the list
              > I tried this and gave me an error
              > *************** *************** *************** ********
              > public RoleForm(int RoleID, List<T> lRole)
              >
              > {
              >
              > InitializeCompo nent();
              >
              > _ID = RoleID;
              >
              > }
              >
              > *************** *************** *************** *************** **
              >
              > ERROR:Error 1 The type or namespace name 'T' could not be found (are you
              > missing a using directive or an assembly reference?)
              >
              > *************** *************** *************** ********
              >
              > "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote
              > in message news:%234RSw4yC GHA.3820@TK2MSF TNGP12.phx.gbl. ..[color=green]
              >> Vivek,
              >>
              >> Again, why not just call a method on the child form, passing the list
              >> to it? It's like passing a parameter to any other method.
              >>
              >> --
              >> - Nicholas Paldino [.NET/C# MVP]
              >> - mvp@spam.guard. caspershouse.co m
              >>
              >> "Vivek" <viveks@xtra.co .nz> wrote in message
              >> news:uWl$N2yCGH A.4004@tk2msftn gp13.phx.gbl...[color=darkred]
              >>> It sure did. I'll have to find out how to pass the list to the child
              >>> form. can you please mention if you know an efficient way.
              >>>
              >>> Thanks
              >>>
              >>>
              >>> "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote
              >>> in message news:e9K7XzyCGH A.4016@TK2MSFTN GP11.phx.gbl...
              >>>> Vivek,
              >>>>
              >>>> Why not pass the List<T> to the child form when you create it from
              >>>> the parent? You can pass it through a constructor, through a property,
              >>>> public field, or method.
              >>>>
              >>>> Hope this helps.
              >>>>
              >>>>
              >>>> --
              >>>> - Nicholas Paldino [.NET/C# MVP]
              >>>> - mvp@spam.guard. caspershouse.co m
              >>>>
              >>>> "Vivek" <viveks@xtra.co .nz> wrote in message
              >>>> news:ubc1gxyCGH A.3708@TK2MSFTN GP12.phx.gbl...
              >>>>> Hi,
              >>>>>
              >>>>> I wish to update the LIST<T> created in PARENT FORM from the CHILD
              >>>>> FORM. Currently I have declared the LIST<Role> as public in my parent
              >>>>> form. What can I do to update the <LIST>?
              >>>>>
              >>>>> Thanks
              >>>>>
              >>>>
              >>>>
              >>>
              >>>[/color]
              >>
              >>[/color]
              >
              >[/color]


              Comment

              • Vivek

                #8
                Re: Update LIST&lt;T&gt; from a different form

                Nicholas, Thanks for your help. I tried renaimg from <T> to <Role> and it
                gives me an error

                *************** *************** *************** *********
                Error 1 Inconsistent accessibility: parameter type
                'System.Collect ions.Generic.Li st<LPADMIN.Clas ses.Role>' is less accessible
                than method 'LPADMIN.Design er.RoleForm.Rol eForm(int,
                System.Collecti ons.Generic.Lis t<LPADMIN.Class es.Role>)' D:\Windows
                Applications\Ag oge\LPADMIN\LPA DMIN\Designer\R oleForm.cs 17 16 LPADMIN
                *************** *************** *************** *************** *************** *************** ***************

                Can you please help?


                "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
                message news:OXqy%23OzC GHA.3876@tk2msf tngp13.phx.gbl. ..[color=blue]
                > Vivek,
                >
                > Unless your class is Generic, you want to do this:
                >
                > public RoleForm(int RoleId, List<Role> lRole)
                >
                > By the way, you should not name your parameter lRole, but rather,
                > Roles. The public naming guidelines indicate that you should do something
                > else.
                >
                > The reason what I typed works is because when you say List<T>, if T
                > isn't a type parameter, then the compiler will look for a type named T.
                > You need to set the specific type for the generic parameter.
                >
                >
                > --
                > - Nicholas Paldino [.NET/C# MVP]
                > - mvp@spam.guard. caspershouse.co m
                >
                > "Vivek" <viveks@xtra.co .nz> wrote in message
                > news:ecR31BzCGH A.516@TK2MSFTNG P15.phx.gbl...[color=green]
                >>I have a class ROLE with all the properties declared. I am adding the
                >>roles to the list
                >> I tried this and gave me an error
                >> *************** *************** *************** ********
                >> public RoleForm(int RoleID, List<T> lRole)
                >>
                >> {
                >>
                >> InitializeCompo nent();
                >>
                >> _ID = RoleID;
                >>
                >> }
                >>
                >> *************** *************** *************** *************** **
                >>
                >> ERROR:Error 1 The type or namespace name 'T' could not be found (are you
                >> missing a using directive or an assembly reference?)
                >>
                >> *************** *************** *************** ********
                >>
                >> "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote
                >> in message news:%234RSw4yC GHA.3820@TK2MSF TNGP12.phx.gbl. ..[color=darkred]
                >>> Vivek,
                >>>
                >>> Again, why not just call a method on the child form, passing the list
                >>> to it? It's like passing a parameter to any other method.
                >>>
                >>> --
                >>> - Nicholas Paldino [.NET/C# MVP]
                >>> - mvp@spam.guard. caspershouse.co m
                >>>
                >>> "Vivek" <viveks@xtra.co .nz> wrote in message
                >>> news:uWl$N2yCGH A.4004@tk2msftn gp13.phx.gbl...
                >>>> It sure did. I'll have to find out how to pass the list to the child
                >>>> form. can you please mention if you know an efficient way.
                >>>>
                >>>> Thanks
                >>>>
                >>>>
                >>>> "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om>
                >>>> wrote in message news:e9K7XzyCGH A.4016@TK2MSFTN GP11.phx.gbl...
                >>>>> Vivek,
                >>>>>
                >>>>> Why not pass the List<T> to the child form when you create it from
                >>>>> the parent? You can pass it through a constructor, through a
                >>>>> property, public field, or method.
                >>>>>
                >>>>> Hope this helps.
                >>>>>
                >>>>>
                >>>>> --
                >>>>> - Nicholas Paldino [.NET/C# MVP]
                >>>>> - mvp@spam.guard. caspershouse.co m
                >>>>>
                >>>>> "Vivek" <viveks@xtra.co .nz> wrote in message
                >>>>> news:ubc1gxyCGH A.3708@TK2MSFTN GP12.phx.gbl...
                >>>>>> Hi,
                >>>>>>
                >>>>>> I wish to update the LIST<T> created in PARENT FORM from the CHILD
                >>>>>> FORM. Currently I have declared the LIST<Role> as public in my parent
                >>>>>> form. What can I do to update the <LIST>?
                >>>>>>
                >>>>>> Thanks
                >>>>>>
                >>>>>
                >>>>>
                >>>>
                >>>>
                >>>
                >>>[/color]
                >>
                >>[/color]
                >
                >[/color]


                Comment

                • Vivek

                  #9
                  Re: Update LIST&lt;T&gt; from a different form

                  I think I have figured out what is wrong


                  "Vivek" <viveks@xtra.co .nz> wrote in message
                  news:%23V3gQdzC GHA.2908@TK2MSF TNGP09.phx.gbl. ..[color=blue]
                  > Nicholas, Thanks for your help. I tried renaimg from <T> to <Role> and it
                  > gives me an error
                  >
                  > *************** *************** *************** *********
                  > Error 1 Inconsistent accessibility: parameter type
                  > 'System.Collect ions.Generic.Li st<LPADMIN.Clas ses.Role>' is less accessible
                  > than method 'LPADMIN.Design er.RoleForm.Rol eForm(int,
                  > System.Collecti ons.Generic.Lis t<LPADMIN.Class es.Role>)' D:\Windows
                  > Applications\Ag oge\LPADMIN\LPA DMIN\Designer\R oleForm.cs 17 16 LPADMIN
                  > *************** *************** *************** *************** *************** *************** ***************
                  >
                  > Can you please help?
                  >
                  >
                  > "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote
                  > in message news:OXqy%23OzC GHA.3876@tk2msf tngp13.phx.gbl. ..[color=green]
                  >> Vivek,
                  >>
                  >> Unless your class is Generic, you want to do this:
                  >>
                  >> public RoleForm(int RoleId, List<Role> lRole)
                  >>
                  >> By the way, you should not name your parameter lRole, but rather,
                  >> Roles. The public naming guidelines indicate that you should do something
                  >> else.
                  >>
                  >> The reason what I typed works is because when you say List<T>, if T
                  >> isn't a type parameter, then the compiler will look for a type named T.
                  >> You need to set the specific type for the generic parameter.
                  >>
                  >>
                  >> --
                  >> - Nicholas Paldino [.NET/C# MVP]
                  >> - mvp@spam.guard. caspershouse.co m
                  >>
                  >> "Vivek" <viveks@xtra.co .nz> wrote in message
                  >> news:ecR31BzCGH A.516@TK2MSFTNG P15.phx.gbl...[color=darkred]
                  >>>I have a class ROLE with all the properties declared. I am adding the
                  >>>roles to the list
                  >>> I tried this and gave me an error
                  >>> *************** *************** *************** ********
                  >>> public RoleForm(int RoleID, List<T> lRole)
                  >>>
                  >>> {
                  >>>
                  >>> InitializeCompo nent();
                  >>>
                  >>> _ID = RoleID;
                  >>>
                  >>> }
                  >>>
                  >>> *************** *************** *************** *************** **
                  >>>
                  >>> ERROR:Error 1 The type or namespace name 'T' could not be found (are you
                  >>> missing a using directive or an assembly reference?)
                  >>>
                  >>> *************** *************** *************** ********
                  >>>
                  >>> "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote
                  >>> in message news:%234RSw4yC GHA.3820@TK2MSF TNGP12.phx.gbl. ..
                  >>>> Vivek,
                  >>>>
                  >>>> Again, why not just call a method on the child form, passing the
                  >>>> list to it? It's like passing a parameter to any other method.
                  >>>>
                  >>>> --
                  >>>> - Nicholas Paldino [.NET/C# MVP]
                  >>>> - mvp@spam.guard. caspershouse.co m
                  >>>>
                  >>>> "Vivek" <viveks@xtra.co .nz> wrote in message
                  >>>> news:uWl$N2yCGH A.4004@tk2msftn gp13.phx.gbl...
                  >>>>> It sure did. I'll have to find out how to pass the list to the child
                  >>>>> form. can you please mention if you know an efficient way.
                  >>>>>
                  >>>>> Thanks
                  >>>>>
                  >>>>>
                  >>>>> "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om>
                  >>>>> wrote in message news:e9K7XzyCGH A.4016@TK2MSFTN GP11.phx.gbl...
                  >>>>>> Vivek,
                  >>>>>>
                  >>>>>> Why not pass the List<T> to the child form when you create it from
                  >>>>>> the parent? You can pass it through a constructor, through a
                  >>>>>> property, public field, or method.
                  >>>>>>
                  >>>>>> Hope this helps.
                  >>>>>>
                  >>>>>>
                  >>>>>> --
                  >>>>>> - Nicholas Paldino [.NET/C# MVP]
                  >>>>>> - mvp@spam.guard. caspershouse.co m
                  >>>>>>
                  >>>>>> "Vivek" <viveks@xtra.co .nz> wrote in message
                  >>>>>> news:ubc1gxyCGH A.3708@TK2MSFTN GP12.phx.gbl...
                  >>>>>>> Hi,
                  >>>>>>>
                  >>>>>>> I wish to update the LIST<T> created in PARENT FORM from the CHILD
                  >>>>>>> FORM. Currently I have declared the LIST<Role> as public in my
                  >>>>>>> parent form. What can I do to update the <LIST>?
                  >>>>>>>
                  >>>>>>> Thanks
                  >>>>>>>
                  >>>>>>
                  >>>>>>
                  >>>>>
                  >>>>>
                  >>>>
                  >>>>
                  >>>
                  >>>[/color]
                  >>
                  >>[/color]
                  >
                  >[/color]


                  Comment

                  Working...