The subject pretty much says it all but what I want to do is create a text entry field inside of a list box at the end of the list when a button is clicked. Any help is welcomed. TIA.
Printable View
The subject pretty much says it all but what I want to do is create a text entry field inside of a list box at the end of the list when a button is clicked. Any help is welcomed. TIA.
How bout a combo box?
just curious, what is the purpose of this?
I don't think it was understood what I was wanting to do. I have a listbox. When a user clicks a command button I want a text box to appear inside the listbox at the very bottom (under the last entry) so that text can be typed. When the user clicks outside of the text box I want the text inside the text box to become the (new) last entry on the list. I suppose the same end result (an new entry at the end of the box) could be achieved using a text box on the form or something like that but I've seen this done and would like to use this method as it's more visual appealling and cuts down on form space used.
I think I know what you mean, this can be done by using a ListView instead of a ListBox with the LabelEdit property set to Automatic (or Manual if you want to activate is using a command button). It fires the BeforeLabelEdit and AfterLabelEdit events, which you can use to determine if the user has changed the label.
Good luck!
Use the SetParent API function.
Code:Private Declare Function SetParent Lib "user32" _
(ByVal hWndChild As Long, ByVal hWndNewParent As _
Long) As Long
Private Sub Form_Load()
SetParent Text1.hWnd, List1.hWnd
End Sub
I just used Matthew's suggestion and tested what you were talking about, hope this is what you needed.Code:Private Declare Function SetParent Lib "user32" _
(ByVal hWndChild As Long, ByVal hWndNewParent As _
Long) As Long
Private Sub Command1_Click()
Text1.Visible = True
Text1.SetFocus
End Sub
Private Sub Form_Load()
SetParent Text1.hWnd, List1.hWnd
Text1.Left = -30
Text1.Top = List1.Height - Text1.Height - 30
End Sub
Private Sub Form_Resize()
List1.Width = Me.ScaleWidth
Text1.Width = List1.Width
Me.Height = 3600
End Sub
Private Sub Text1_LostFocus()
List1.AddItem Text1.Text, List1.ListCount
Text1.Visible = False
Text1.Text = ""
End Sub
Thanks guys...that's exactly what I was after. I hate to sound greedy but can anyone tell me how I can place it right under the last entry so that the textbox will pop-up in the same place that the text in contains will appear after Command1_LostFocus() is called?? Many thanks.
-Adam
p.s. If not it's no big deal but if so that would be great.