Can someone please tell me what I'm doing wrong here?
I'm trying to place all the items from a combobox into an array, but it doesn't seem to be working for me.
My code:
Dim name as string
Dim list As New ArrayList
For i = 0 To form.cbSMTPAccounts.Items.Count - 1
name = form.cbSMTPAccounts.Items(i).text.ToString
list.Add(name)
I keep getting "Public member 'text' on type 'String' " error,
Incidentally, Once this array is working properly, I would like to convert it to a single string if possible...if that makes any sense
kevin
Loading
VulpesPosted Sep 1, 2011, 3:52 PM
Try this instead for the last line:
Dim combined As String = String.Join(", ", CType(list.ToArray(GetType(String)), String()))
VulpesPosted Sep 1, 2011, 4:31 PM
Anyway, to get the string back into the combobox you could do:
Dim items() As String = combined.Split(New String() {", "}, StringSplitOptions.None)
form.cbSMTPAccounts.DataSource = items
or, if you'd prefer to leave the combobox unbound, just replace the second line with:
For Each item As String In items
form.cbSMTPAccounts.Items.Add(item)
Next
As a further alternative, I think this one should work as well:
form.cbSMTPAccounts.Items.AddRange(items)
Kevin DavisPosted Sep 1, 2011, 3:57 PM
Side note: How could I get that "string" back into the combobox?
Kevin DavisPosted Sep 1, 2011, 3:47 PM
VulpesPosted Sep 1, 2011, 2:56 PM