nothing better than a good book, or at least MSDN there are many nice tutorials online
spotty gave you a very correct answer but for next time question edit this line
Dim x(i - 1) As Object
more over here its the tostring way
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim items(ListBox1.SelectedItems.Count - 1) As String
Dim index As Integer = 0 For Each item As Object In ListBox1.SelectedItems items(index) = item.ToString() index += 1 Next
'for test
For Each item As String In items MessageBox.Show(item) Next
End Sub
Although the loop was to i-1 which meant I just had an extra element in the array but well caught.
For ... Next construct or For Each constructs both work and I think svekke has enough solutions now to answer his question or at least should now be able to modify these for his own applications purpose.
The help files have some help and samples on using the .Items property of the list box. Is that not working for you Usually, when I need help on a specific control, I select the control and press F1 - it'll bring up help for that control. Most controls have a lot of code samples in both VB and C#.
That is the quickest way for you to get help on how to use a control.
The listbox has an items collection. Just iterate over it, or use the indexes if you know them, and copy them to a list. The list should have a ToArray method when you're done, at least I know ArrayList did.
i don't understand what record you want to take to array , just the selected items or do you want to iterate through all items and select each item start with foo for example your question is not clear
anyway you can find the documentation by using help or you can get it online www.msdn2.microsoft.com type in the search box what do you want to search for then go
if you want just the selected items in the textbox you can take a look to the next link
You have a collection of selectedItems that you can iterate through.
If you want to write the selected items to an array then you will process them as you would any other array.
Example will create an array of the selectedItem objects. These may include more than just the displayed string in the listbox. If you want to just get the strings of the items in the listbox then you could dim the array as string and get the selectedItem(ix).tostring
Dim i As Integer i = Me.ListBox1.SelectedItems.Count If i > 0 Then Dim x(i) As Object Dim ix As Integer For ix = 0 To i - 1 x(ix) = Me.ListBox1.SelectedItem(ix) Next End If
Read line listbox to variable
jmoser
Evian_
hi, svekke
nothing better than a good book, or at least MSDN there are many nice tutorials online
spotty gave you a very correct answer but for next time question edit this line
Dim x(i - 1) As Object
more over here its the tostring way
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim items(ListBox1.SelectedItems.Count - 1) As String Dim index As Integer = 0
For Each item As Object In ListBox1.SelectedItems
items(index) = item.ToString()
index += 1
Next 'for test For Each item As String In items
MessageBox.Show(item)
Next End Sub
hope this helps
Vikram Bade
Did you find the listbox.items property in the help files There's an example there in looping through the items in a list box.
Egypt Develover
Agreed shakalama
The dim statement should have actually been i-1.
Although the loop was to i-1 which meant I just had an extra element in the array but well caught.
For ... Next construct or For Each constructs both work and I think svekke has enough solutions now to answer his question or at least should now be able to modify these for his own applications purpose.
phatrice
The help files have some help and samples on using the .Items property of the list box. Is that not working for you Usually, when I need help on a specific control, I select the control and press F1 - it'll bring up help for that control. Most controls have a lot of code samples in both VB and C#.
That is the quickest way for you to get help on how to use a control.
Wentzel
I need it quickly!!
It's for a project and must be finished this week
Melipao
where i can read about it
Aerodes
dadaguo3000
hi,
i don't understand what record you want to take to array , just the selected items or do you want to iterate through all items and select each item start with foo for example your question is not clear
anyway you can find the documentation by using help or you can get it online www.msdn2.microsoft.com type in the search box what do you want to search for then go
if you want just the selected items in the textbox you can take a look to the next link
http://msdn2.microsoft.com/en-us/library/system.windows.forms.listbox.selectedindices(VS.80).aspx
hope this helps
InVitro
But thanks to al who helped me
but now i need to write the array to an existing excel file
The array must been write to colum A4 to A19
MrSnipey
But how must i write the selected items to an array
praefex
You have a collection of selectedItems that you can iterate through.
If you want to write the selected items to an array then you will process them as you would any other array.
Example will create an array of the selectedItem objects. These may include more than just the displayed string in the listbox. If you want to just get the strings of the items in the listbox then you could dim the array as string and get the selectedItem(ix).tostring
Dim i As Integer
i = Me.ListBox1.SelectedItems.Count
If i > 0 Then
Dim x(i) As Object
Dim ix As Integer
For ix = 0 To i - 1
x(ix) = Me.ListBox1.SelectedItem(ix)
Next
End If
ckm
I don't find him
Cory.Isakson