Results 1 to 7 of 7

Thread: remove a control

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 1999
    Location
    belgium
    Posts
    74
    With this code, I've made a control at runtime.

    Set btnObj = Controls.Add("VB.ComboBox", sControlName)
    With btnObj
    .Visible = True
    .Width = 2000
    .Top = 210 + (i * 350)
    .Left = 5500
    .ForeColor = vbBlack
    .Text = ""
    End With

    Now I want to remove it. So I thought to set it equal to Nothing:

    Set btnObj = Nothing

    The problem is, that the control is still on my form.

    How can I realy remove it?

  2. #2
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    Just a thought .
    Change it's visible property and then set it to nothing .






    []P
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  3. #3
    New Member
    Join Date
    Oct 2000
    Posts
    10
    try "Unload btnObj"

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 1999
    Location
    belgium
    Posts
    74
    The Unload solution doesn't seems to work.


    first I've set the visible property to false
    and then I set it on nothing.


    When I want to add a new control with te same name as the one I deleted, I get an error which said "Object with this name already exists".
    So it seems that the 'Nothing' not realy destroys the object.

    Some solution?

  5. #5
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    As it is a Collection you should have access to the Remove method. i.e. Controls.Remove sControlName

    Cheers,

    P.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  6. #6
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Try this api call!

    Code:
    Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
    
    Private Sub RemoveMe(Handle As Long)
    DestroyWindow Handle
    End Sub
    
    'usage:
    'RemoveMe btnObj.hWnd
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  7. #7
    Guest
    Controls has a property called Remove.

    Code:
    Controls.Remove ("sControlName")

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