• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

How do I add a line like "hello" to a listbox in vb.net?

How do I add a line like "hello" to a listbox in vb.net?

lbUsers.add("Jessie")

something like that?
0
Hepen
Asked:
Hepen
  • 4
  • 3
1 Solution
 
LordWabbitCommented:
would probably be more like listbox1.Items.Add("hello") a lbl is usually short for label which when then be lblUsers.Text
0
 
HepenAuthor Commented:
      Dim pendingClient As TcpClient
        Dim nameOfClient As String
        pendingClient = Listener.AcceptTcpClient()
        reader = New System.IO.StreamReader(pendingClient.GetStream)
        nameOfClient = reader.ReadLine()

        test.Add(nameOfClient)

        MessageBox.Show(nameOfClient & " has just signed in.")

        lbUsers.DataSource = test

When I do that the listbox doesn't show anything even though nameofclient has a name in it.
0
 
HepenAuthor Commented:
I should add that I'm working with threads.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CDCOPCommented:
In your code example you have:
test.Add(nameOfClient)

not
listbox1.Items.Add("hello")

You forgot items like Lord said.
0
 
HepenAuthor Commented:
Wait I can't even get a listbox to add simple text in a simple vb.net windows app.

How do you do that exactly?
0
 
HepenAuthor Commented:
Can you guys just paste a simple vb.net form1 that adds text to a listbox?
0
 
CDCOPCommented:
1) Drag a listbox onto the form.
2) Rename it to: lst_1
3) Double click on the grey form (form load event)
4) Paste this code and then complie:
        lb_1.Items.Add("Test Line 1")
        lb_1.Items.Add("Test Line 2")
        lb_1.Items.Add("Test Line 3")

Make sure you get the list box and not a different control!
0
 
CDCOPCommented:
Thanks for points and grade.

Were you using the wrong control?
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now