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

VulpesRank #55 · 29.2K reputationPosted Sep 1, 2011, 11:52 AM EDT
Try this instead for the last line:
Dim combined As String = String.Join(", ", CType(list.ToArray(GetType(String)), String()))
VulpesRank #55 · 29.2K reputationPosted Sep 1, 2011, 10:56 AM EDT
Kevin Davis52 reputationPosted Sep 1, 2011, 11:47 AM EDT
Kevin Davis52 reputationPosted Sep 1, 2011, 11:57 AM EDT
Side note: How could I get that "string" back into the combobox?
VulpesRank #55 · 29.2K reputationPosted Sep 1, 2011, 12:31 PM EDT
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)