C# app: what's wrong with my control here?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • leimeisei
    New Member
    • Aug 2008
    • 4

    C# app: what's wrong with my control here?

    Alright, I was a PHP and flash developer before .NET, and so I am used to using dynamic variables in loop situations like these. But let me explain what I'm trying to do.

    Basically, there is a custom control that loops through a List<Product> when it is received, and displays smaller "UserContro l2" controls for every product in that list. However, when I run this code for some reason, the UserControl2 objects do not show up. No idea why. Here's the method:

    private List<UserContro l2> controlist = new List<UserContro l2>();

    public void SetProductSourc e( Product[] ProductSource )
    {


    for (int ii = 0; ii < ProductSource.L ength; ++ii)
    {
    UserControl2 newcontrol = new UserControl2();

    newcontrol.Name = "NewControl " +ii.ToString();

    newcontrol.Loca tion = new Point( 0, (HeightPerItem + ItemSpacing) * ii );
    newcontrol.Size = new Size( 676, 158 );
    newcontrol.SetP roduct( ProductSource[ii] );
    newcontrol.Visi ble = true;
    newcontrol.Brin gToFront();
    controlist.Add( newcontrol );
    }
    }
  • leimeisei
    New Member
    • Aug 2008
    • 4

    #2
    My apologies, I did not set the Parent attribute on the objects I was creating. Delete this question if you'd like.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      You also could have added the controls to the control collection on the parent object.
      Such as a this.Controls.A dd() (or in VBNET me.Controls.Add () )

      Comment

      Working...