Display Listbox items

choudhmh

Member
Joined
Jul 18, 2006
Messages
12
Programming Experience
Beginner
hi Guys,
i'm having issues trying to show listbox items into a text box. I have a list box item, when any of these items are selected from the collection (using VS.NET) i need that item to be shown in a text box. Can someone help me with that.

Thanks,
M
 
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
TextBox1.Text = ListBox1.SelectedItem
End Sub
 
What i meant was i want to add up the values of all the listboxes inside the textbox.
can someone indicate to me how i will add up the values of selected listbox item and display the answer on the text box
Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox6.TextChanged
TextBox6.Text = ListBox1.SelectedItem + ListBox5.SelectedItem
End Sub
 
Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox6.TextChanged
dim i as integer =0
for j = 0 to listbox1.items.count-1
i+= listbox1.selectedindex(j)
next
TextBox6.Text = i
End Sub
 
iam sorry ,below is the correct code

Dim j As Integer
For i = 0 To ListBox1.Items.Count - 1
j += CInt(ListBox1.Items.Item(i).ToString)
Next
textbox1.text = j
 
the code you gave me is not functioning, it loops around and add all the numbers from one listbox.

I have several listbox what i want is 'whatever items are selected from the listboxes, add all of them up then give me the final answer i.e. listbox1.selecteditems = 1, listbox2.selceteditem=2, listbox3.selecteditem = 5 =
textbox.text=10;'

thi Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim j As Integer
Dim i As Integer

For i = 0 To ListBox1.Items.Count - 1
j += CInt(ListBox1.Items.Item(i).ToString)
Next
TextBox6.Text = j
End Subs is what i have at present from you:


hope this makes sense.

Thanks
 
Back
Top