|
-
May 6th, 2004, 01:53 PM
#1
Thread Starter
Hyperactive Member
Adding text to a listbox from a textbox *[RESOLVED]*
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.
Last edited by RealNickyDude; May 7th, 2004 at 09:45 AM.
-
May 6th, 2004, 02:21 PM
#2
New Member
try this out....
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!!!
-
May 6th, 2004, 02:24 PM
#3
Thread Starter
Hyperactive Member
Isn't it possible to do something like this (when a button is clicked)
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
This doesn't work incidentally, it says:
C:\My Programs\VisualBasic\MACK\InputSection.vb(86): Reference to a non-shared member requires an object reference.
-
May 6th, 2004, 02:34 PM
#4
New Member
hmmmm.......
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?
-
May 6th, 2004, 03:46 PM
#5
Thread Starter
Hyperactive Member
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
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.
-
May 6th, 2004, 04:02 PM
#6
PowerPoster
Hi,
Ref your original post, this was covered in depth in thread
http://www.vbforums.com/showthread.p...hreadid=288791
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
May 6th, 2004, 04:52 PM
#7
Thread Starter
Hyperactive Member
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?
-
May 7th, 2004, 05:50 AM
#8
Thread Starter
Hyperactive Member
-
May 7th, 2004, 08:12 AM
#9
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
-
May 7th, 2004, 08:43 AM
#10
Thread Starter
Hyperactive Member
Thanks Negative0
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|