|
-
May 9th, 2003, 02:14 PM
#1
Thread Starter
Junior Member
Hashtable & Combo Box
Hi,
I've created a hashtable which contains a list of countries with the key being the ISO country code and the value being the country name.
In ASP.NET I've attached it to a drop down list as so:
ddlCountries.DataSource = myHashtable
ddlCountries.DataTextField = "Value"
ddlCountries.DataValueField = "Key"
This works absolutely fine.
Now when I try to do a similar thing in a Windows Form using a combo box it throws an exception:
"System Exception: Complex DataBinding accepts as a data source either an IList or an IListSource"
I guess that its down to the type of collection, but is there anyway of binding a hashtable to a combo box?
Or, is there any easy way to convert the hashtable to something the combo box WILL accept?
Any help would be appreciated.
Thanks.
-
May 9th, 2003, 02:27 PM
#2
Thread Starter
Junior Member
Great when you figure it out
Dim enurtrCountries As IDictionaryEnumerator = myHashtable.GetEnumerator
Dim drCountry As DataRow
Dim dtCountries As New DataTable
dtCountries.Columns.Add("Key")
dtCountries.Columns.Add("Value")
Do While enurtrCountries.MoveNext
drCountry = dtCountries.NewRow
drCountry("Key") = enurtrCountries.Key
drCountry("Value") = enurtrCountries.Value
dtCountries.Rows.Add(drCountry)
Loop
ddlCountry.DataSource = dtCountries
ddlCountry.DisplayMember = "Value"
ddlCountry.ValueMember = "Key"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|