Results 1 to 10 of 10

Thread: Adding text to a listbox from a textbox *[RESOLVED]*

  1. #1

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435

    Talking 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.
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  2. #2
    New Member
    Join Date
    Apr 2004
    Posts
    12

    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!!!

  3. #3

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    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.
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  4. #4
    New Member
    Join Date
    Apr 2004
    Posts
    12

    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?

  5. #5

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    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.
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  7. #7

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    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?
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  8. #8

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    Anybody?
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  9. #9
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    VB Code:
    1. Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
    2.         If e.KeyCode = 13 Then
    3.             ListBox1.Items.Add(TextBox1.Text)
    4.             TextBox1.Text = ""
    5.  
    6.         End If
    7.     End Sub

  10. #10

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    Thanks Negative0
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

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