4 Replies - 2184 Views - Last Post: 23 July 2014 - 02:39 AM Rate Topic: -----

#1 Lapin Noir   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 18-July 14

How to have selected item in ListBox to display in TextBox?

Posted 22 July 2014 - 01:24 AM

Here is my code
Public Class TestForm

    Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

    End Sub

    Private Sub TestForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim testSelection As IO.StreamReader
        If IO.File.Exists("TESTS.txt") Then
            testSelection = IO.File.OpenText("TESTS.txt")
            Do Until testSelection.EndOfStream
                TestList.Items.Add(testSelection.ReadLine)

            Loop
        Else
            Dim message As String
            message = "Not found"
            MessageBox.Show(message)
        End If

        TestBox.Text = TestList.SelectedItem
    End Sub

    Private Sub TestBox_TextChanged(sender As Object, e As EventArgs) Handles TestBox.TextChanged

    End Sub
End Class



How can I make it so that when I click on an item displayed in the listbox "TextList" it will display in the textbox "TestBox"?

Thanks!

TESTS.txt is a text file consisted of two lines - Test A and Test B.

Is This A Good Question/Topic? 0
  • +

Replies To: How to have selected item in ListBox to display in TextBox?

#2 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1505
  • View blog
  • Posts: 3,808
  • Joined: 01-February 13

Re: How to have selected item in ListBox to display in TextBox?

Posted 22 July 2014 - 02:46 AM

Hi,
This looks like homework so, i can`t really give you the code to do this but, you would use the ListBox.SelectedIndexChanged Event to capture when an item is selected in the ListBox. Then use the ListBox.SelectedItem Property to get the selected item`s text.

There is an example at the bottom of the pages in the links that shows how to get the selected item as a string. You would assign that to the TextBox.Text property. :)
Was This Post Helpful? 1
  • +
  • -

#3 Lapin Noir   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 18-July 14

Re: How to have selected item in ListBox to display in TextBox?

Posted 22 July 2014 - 08:56 PM

View PostIronRazer, on 22 July 2014 - 02:46 AM, said:

Hi,
This looks like homework so, i can`t really give you the code to do this but, you would use the ListBox.SelectedIndexChanged Event to capture when an item is selected in the ListBox. Then use the ListBox.SelectedItem Property to get the selected item`s text.

There is an example at the bottom of the pages in the links that shows how to get the selected item as a string. You would assign that to the TextBox.Text property. :)/>


I don't need the exact code, but I would like to have someone to point me the right direction :helpsmilie:

Anyway thank you for your link! However I notice the SelectedIndexChanged only works to display selected item from the listbox to another listbox. What are other option if I would like to have the listbox item displayed in a textbox :helpsmilie:
Was This Post Helpful? 0
  • +
  • -

#4 Lapin Noir   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 18-July 14

Re: How to have selected item in ListBox to display in TextBox?

Posted 22 July 2014 - 09:15 PM

View PostLapin Noir, on 22 July 2014 - 08:56 PM, said:

View PostIronRazer, on 22 July 2014 - 02:46 AM, said:

Hi,
This looks like homework so, i can`t really give you the code to do this but, you would use the ListBox.SelectedIndexChanged Event to capture when an item is selected in the ListBox. Then use the ListBox.SelectedItem Property to get the selected item`s text.

There is an example at the bottom of the pages in the links that shows how to get the selected item as a string. You would assign that to the TextBox.Text property. :)/>/>


I don't need the exact code, but I would like to have someone to point me the right direction :helpsmilie:/>

Anyway thank you for your link! However I notice the SelectedIndexChanged only works to display selected item from the listbox to another listbox. What are other option if I would like to have the listbox item displayed in a textbox :helpsmilie:/>


Thank you!!! Got it finally!!!!
Was This Post Helpful? 0
  • +
  • -

#5 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1505
  • View blog
  • Posts: 3,808
  • Joined: 01-February 13

Re: How to have selected item in ListBox to display in TextBox?

Posted 23 July 2014 - 02:39 AM

Hi,
Sorry i missed your question but, i am glad to here you got it figured out. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1