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. can i dynamicly access object from name of object

can i dynamicly access object from name of object

Scheduled Pinned Locked Moved C#
helptutorial
5 Posts 4 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.
  • C Offline
    C Offline
    combo_ci
    wrote on last edited by
    #1

    hi i have 2 form in my program publis object from form2 for example "Frm_User" that new in load of mainform and have a filed for example "AllowEdit" i can access to this filed by Frm_User.AllowEdit but i want to find a way that access "AllowEdit" by know name of this filed in other form it mean that i want find a way to dynamically access obj of form2 "Frm_User" by Name and then change that field in mainForm can any one help me thnx

    J S 2 Replies Last reply
    0
    • C combo_ci

      hi i have 2 form in my program publis object from form2 for example "Frm_User" that new in load of mainform and have a filed for example "AllowEdit" i can access to this filed by Frm_User.AllowEdit but i want to find a way that access "AllowEdit" by know name of this filed in other form it mean that i want find a way to dynamically access obj of form2 "Frm_User" by Name and then change that field in mainForm can any one help me thnx

      J Offline
      J Offline
      Jordon4Kraftd
      wrote on last edited by
      #2

      Have you tried casting the object? If the object is different everytime and you can't edit the objects to use an interface with "allowEdit" then maybe you can try using "reflection" methods to get access. Look up those things then ask for specific help.

      C 1 Reply Last reply
      0
      • J Jordon4Kraftd

        Have you tried casting the object? If the object is different everytime and you can't edit the objects to use an interface with "allowEdit" then maybe you can try using "reflection" methods to get access. Look up those things then ask for specific help.

        C Offline
        C Offline
        combo_ci
        wrote on last edited by
        #3

        i know with reflection we can access all property and method with the instance of the object but my problem is i want to create instance of instance of the object from a string that contain name of that object for example : i know that object of from2 is "Frm_User" and string whith this code

        string temp="Frm_User";

        can i access the object of form 2 with temp?and change property and and field of that?

        L 1 Reply Last reply
        0
        • C combo_ci

          hi i have 2 form in my program publis object from form2 for example "Frm_User" that new in load of mainform and have a filed for example "AllowEdit" i can access to this filed by Frm_User.AllowEdit but i want to find a way that access "AllowEdit" by know name of this filed in other form it mean that i want find a way to dynamically access obj of form2 "Frm_User" by Name and then change that field in mainForm can any one help me thnx

          S Offline
          S Offline
          softty
          wrote on last edited by
          #4

          You can probably, expose AllowEdit through a public property and set it from your code

          love2code

          1 Reply Last reply
          0
          • C combo_ci

            i know with reflection we can access all property and method with the instance of the object but my problem is i want to create instance of instance of the object from a string that contain name of that object for example : i know that object of from2 is "Frm_User" and string whith this code

            string temp="Frm_User";

            can i access the object of form 2 with temp?and change property and and field of that?

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Have a look at Activator.CreateInstance(). :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


            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