Results 1 to 5 of 5

Thread: [RESOLVED] [2005] clear controls

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    35

    Resolved [RESOLVED] [2005] clear controls

    I want all of my dynamically build controls away of my panel

    but when i do this:

    Code:
    Me.Pnl_step3.Controls.Clear()
    and i return to my form the controls are still there

    what i'm doing wrong??

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] clear controls

    I can't tell you why your controls are still there because that code will clear all child controls from the specified container. It's my guess that you're specifying the wrong container.

    That said, you have another problem there. By simply clearing the controls like that you are creating a resource leak. You MUST dispose all those controls before discarding them like that:
    vb.net Code:
    1. For Each ctl As Control In Me.Pnl_step3.Controls
    2.     ctl.Dispose()
    3. Next ctl
    4.  
    5. Me.Pnl_step3.Controls.Clear()
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    35

    Re: [2005] clear controls

    thx
    i tried this but the result is still the same

    Do you know another solution??

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] clear controls

    There is no other solution required because there is no problem. The code provided will do EXACTLY what it's supposed to. Either you are not actually executing the code or else you're specifying the wrong Panel. You need to debug your code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    35

    Re: [2005] clear controls

    owkay thx
    i think i've found the problem probably my array isn't empty when i reload the page

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width