Bringing Dynamic Controls to the Front

samsmithnz

Senior Contributor
Joined
Jul 22, 2003
Messages
1,038
Location
Boston
I have a Dynamic listbox that I am creating, it's going to be a sort of popup list that you can select from and filters as you're typing. It all works pretty well, except that it's always in the back and a .BringtoFront doesn't seem to do ANYTHING.

Anyone have a clue what I'm doing wrong?

Code:
        'add the dropdown list
        lstDropDown = New ListBox
        With lstDropDown
            .Top = txtDisplayTextBox.Top + txtDisplayTextBox.Height
            .Left = txtDisplayTextBox.Left
            .Height = 95
            .Width = txtDisplayTextBox.Width
            .Visible = True
            .BringToFront()
        End With
        frmParent.Controls.Add(lstDropDown)
 
I don't know why it won't come to the front...

But I do have one alternative suggestion I got from looking at the C# Express 2005 Beta IDE (they have a small graphical bug where the intellisence popup is in a form with no title or control box so it’s just the form and resizing handles with a list-box set to fill the form)

But the list-box looks like it is set to the full height of the form because it’s missing the 4 pixels not accounted for by the resizing handles on the borders.

Anyway you could try putting your list-box in a form with no title or control box.
That way you could give it the ability to be resized too and you should have no trouble bringing it to the front.

P.S. Sorry if that’s not what you meant.

The Red Duke
 
One suggestion I can make. I've used (in C# but that shouldnt matter) the BringToFront method and it did work, but I added the control to the forms collection of controls before calling BringToFront. So maybe you can change that..

Would be something like this:
Code:
...... bit of code i didnt bother with copying ;).
  .Width = txtDisplayTextBox.Width
  .Visible = True
End With
frmParent.Controls.Add(lstDropDown)
lstDropDown.BringToFront()
 
Yeah, you do need to add it to the control collection before bringing it in front. Otherwise it does not have a collection of controls that it can be brought in front of.
 
Back
Top