Hello! I have a Real problem!
I would like do this:(retrieve the text)
Textbox4.text= listbox1.items(1)
But it dont work ?!!
I looked for in the web a way but i failed every time!
So i Ask here some help🥺 !
Thank you in advance for your answer!❤️
Printable View
Hello! I have a Real problem!
I would like do this:(retrieve the text)
Textbox4.text= listbox1.items(1)
But it dont work ?!!
I looked for in the web a way but i failed every time!
So i Ask here some help🥺 !
Thank you in advance for your answer!❤️
"it won't work" could mean any number of things. You need to actually explain the issue in detail, including what actually happens. If there's an error message, tell us what it is. The code you have would work under certain circumstances and not others, but you've not bothered to tell us what the actual circumstances are here. Most importantly, how EXACTLY was the ListBox populated in the first place and what EXACTLY do you expect to happen. You know, the information relevant to the issue. We could guess at a solution and we might even guess right, but we might also guess wrong. Just don't make us guess at all.
i have at least one item but this item(s) are names in a simple list.Quote:
second, do you have at least 2 items in your listbox ?
after, i have to try this :
edit: this code above doesn't work!Code:TextBox4.Text = ListBox1.GetItemText(ListBox1.Items(1))
option strict = off , must i change on ON! this setting is important?
We need the description of the error to know exactly what happens not just "it doesn't work".
yes you should put option strict = on, that will force you to write correct code and do the correct conversions yourself and not expecting the machine to do it for you.
If you have only one item
will generate an error as the list start at 0Code:Textbox4.text= listbox1.items(1).tostring
The ListBox's Text property (documentation) may be what you're wanting, though admittedly I am making several assumptions.
Try using the following code:
Does this provide you with the expected result?Code:TextBox4.Text = ListBox1.Text
Also, I wanted to mention that if you want to keep your code formatted then please use the [CODE] BB tag. There is more information in my signature on code tags.
i would like to write one item from listbox to textbox .
example: if the listbox.item(1) = franck the textox.text = "frank"
or if the listbox.item(5) = Sarah the textox.text = "Sarah"
it looks simple but in real, it is a bit hard!
i am trying to uest this by Delaney:
Textbox4.text= listbox1.items(1).tostring
wait and see...
I don't think you took any of my advice ranging from using the Text property to proper forum etiquette by using code tags. If you cannot follow those simple instructions then I apologize, but I must remove myself from this thread.
so if I understand well, you have a listbox with names. When you select a name in the listbox, you want to show it in a textbox, right ?
Create a new project with a form, a texbox and a listbox
Code:Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim list_name As New List(Of String) From {"Pierre", "Paul", "Jaques"} 'just a way to create the list of name, there are plenty other way
ListBox1.DataSource = list_name 'bind the list to the listbox
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim lb As ListBox = DirectCast(sender, ListBox)
If lb.SelectedIndex > -1 Then
TextBox1.Text = lb.Items(lb.SelectedIndex).ToString
End If
End Sub
End Class
THANK YOU very much! i see what i must do hence my code is inside a "timer". So, the question is "what term must i move out "lb.selecteindex" to have the same result? the listbox1_selectedindex is useless in my case(the index is not unknown).i suggest to put :
Dim lb As ListBox = DirectCast(sender, ListBox)
If lb.SelectedIndex > -1 Then
TextBox1.Text = lb.Items(listbox1.items(0)).ToString
End If
other try:
Dim t As Integer
Dim name(t) As String
For t = 1 To t = 13
name(t) = ListBox7.Items(t)
Next
TextBox1.Text = name(0)
i thank you again! we advance quickly!