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. Copying UserControl Variables

Copying UserControl Variables

Scheduled Pinned Locked Moved C#
helpquestion
3 Posts 2 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.
  • T Offline
    T Offline
    TheBlindWatchmaker
    wrote on last edited by
    #1

    Hi! I have a few instances (say 10) of a UserControl, each with 5 properties, on a Form. I want to implement a "Copy From" function that works the following way: 1. The user can right click on any UserControl. The right click menu allows the user to select a Copy From menu item which springs up a ToolStripComboBox with a list of other similar controls. 2. Once the user selects an instance of the UserControl in the ToolStripComboBox, that UserControl's properties are to be copied to the current UserControl. Each UserControl has a ControlID property that is unique to it (listed in an eControlID enum.) This property will not be copied over. However, the ToolStripComboBox is populated with all the IDs (say A...Z) to help the user identify the UserControl whose properties he wants copied. I have got this far: private void ContextMenuCopyFrom_SelectedIndexChanged(object sender, EventArgs e) { this.ControlID= (eControlID)ContextMenuCopyFrom.SelectedIndex; } How do I actually figure out which UserControl has been selected to copy from and then copy the properties. I figure it'll be something like this.Property1 = UserControlSelected.Property1; this.Property2 = UserControlSelected.Property2; // etc

    A 1 Reply Last reply
    0
    • T TheBlindWatchmaker

      Hi! I have a few instances (say 10) of a UserControl, each with 5 properties, on a Form. I want to implement a "Copy From" function that works the following way: 1. The user can right click on any UserControl. The right click menu allows the user to select a Copy From menu item which springs up a ToolStripComboBox with a list of other similar controls. 2. Once the user selects an instance of the UserControl in the ToolStripComboBox, that UserControl's properties are to be copied to the current UserControl. Each UserControl has a ControlID property that is unique to it (listed in an eControlID enum.) This property will not be copied over. However, the ToolStripComboBox is populated with all the IDs (say A...Z) to help the user identify the UserControl whose properties he wants copied. I have got this far: private void ContextMenuCopyFrom_SelectedIndexChanged(object sender, EventArgs e) { this.ControlID= (eControlID)ContextMenuCopyFrom.SelectedIndex; } How do I actually figure out which UserControl has been selected to copy from and then copy the properties. I figure it'll be something like this.Property1 = UserControlSelected.Property1; this.Property2 = UserControlSelected.Property2; // etc

      A Offline
      A Offline
      atuldeore
      wrote on last edited by
      #2

      You can go through the Controls collection of the form and check the type of control. If the control is of the same type of your user control, match the ControlId with the controlId selected in the combo. If matches, thats the control user wanted.

      Every bit counts

      ADD

      T 1 Reply Last reply
      0
      • A atuldeore

        You can go through the Controls collection of the form and check the type of control. If the control is of the same type of your user control, match the ControlId with the controlId selected in the combo. If matches, thats the control user wanted.

        Every bit counts

        ADD

        T Offline
        T Offline
        TheBlindWatchmaker
        wrote on last edited by
        #3

        Is there any way of doing this without using a collection of controls? Can I match the SelectedIndex to a member of the enum and then copy the properties of that particular object?

        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