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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. "Child is not a child control of this parant"

"Child is not a child control of this parant"

Scheduled Pinned Locked Moved C#
help
2 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.
  • K Offline
    K Offline
    kakanis
    wrote on last edited by
    #1

    Hi I created custom control for panel.My requirment is it accepet only one control in it,for this in oncontroladded i wrote the code if(controls.count>1) { controls.RemoveAt(1); } it is working but i am getting "Child is not a child control of this parant" please Help me

    L 1 Reply Last reply
    0
    • K kakanis

      Hi I created custom control for panel.My requirment is it accepet only one control in it,for this in oncontroladded i wrote the code if(controls.count>1) { controls.RemoveAt(1); } it is working but i am getting "Child is not a child control of this parant" please Help me

      L Offline
      L Offline
      LongRange Shooter
      wrote on last edited by
      #2

      You are not clearly defining your problem which makes it hard for anyone to answer this. Here is what I think you are saying: You have a panel that can have a control added to it. (It does not matter if it is your control or a framework control) So you have logic as follows:

        Panel workarea = new Panel;
        workarea.OnControlAdded += new EventHandler( LimitControlsHandler );
        workarea.Controls.Add( myCustomControl );
      

      So this will then raise an event everytime a new control is added to the panel. So now when that happens your logic should be as follows:

      public void LimitControlHandler(object sender, EventArgs args)
      {
            if ( workarea.Controls.Count > 1 )
               workarea.Controls.RemoveAt(1);
      }
      

      Assuming that the RemoveAt is totally valid logic for the Panel, then your logic should work just fine. Look at what I've listed here and see where your code differs. Then troubleshoot it. It is difficult to tell you what you are doing wrong with the poor amount of information you are providing in this question.

      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