I have a textbox on one form and a listbox on another. How do I have it so the user can enter a number in the textbox on form2, press enter and have the number inserted in the correct position in the listbox on form1.
Printable View
I have a textbox on one form and a listbox on another. How do I have it so the user can enter a number in the textbox on form2, press enter and have the number inserted in the correct position in the listbox on form1.
On the form with the text box:
'creates a new instance of your second form
Dim myForm2 As New Form2()
'Declares variable to store your number
Dim number as Double
'loads value from textbox into variable and sends it to second form
number = txtNum.text
myForm2.Num = number
on second form with list box hince "Form2" from above
'declares variable to recieve value from first form
Dim m_Number As Double
'this doesn't have to be writeonly but is designed just to get the value from the first form without returning any values back to it
Public WriteOnly Property Num()
Set(ByVal Value)
m_Number = Value
End Set
End Property
'list box to display result
lstDisplay.items.add(m_Num)
Hope this helps!!!
Isn't it possible to do something like this (when a button is clicked)
This doesn't work incidentally, it says:Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form1.lstSectionList.additem(Format(tbxInputSecNum, "00#"))
Me.Close()
End Sub
C:\My Programs\VisualBasic\MACK\InputSection.vb(86): Reference to a non-shared member requires an object reference.
I don't believe so because the list box on the first form is entirely private to that form from what I understand, I may be wrong on this but this is just what I understand to be true. Thus the reason for your error is because you are trying to reference an object (the list box) that isn't shared or public. Did the code I posted not work or are you just trying to do it a different way?
I haven't tried it yet ;)
I've actually changed it now, the textbox is on the same form now (it's very much in the "bung controls everywhere and see what it looks like" stage :p
I now have a different problem, I want to type text into this text box then add it to a listbox when ENTER / RETURN is pressed.
Hi,
Ref your original post, this was covered in depth in thread
http://www.vbforums.com/showthread.p...hreadid=288791
Thanks Taxes, i'll bear that in mind, but could or anyone you point me in the right direction about typing text into a text box then add it to a listbox when ENTER / RETURN is pressed?
Anybody?
VB Code:
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown If e.KeyCode = 13 Then ListBox1.Items.Add(TextBox1.Text) TextBox1.Text = "" End If End Sub
Thanks Negative0 :bigyello: