473,395 Members | 2,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

populate a listbox with a hashtable

Hi all,
Is it possible to populate a listbox from a hashtable (complexbind) where
the ValueMember of the listbox maps to the "key" member of the hashtable AND
the DisplayMember of the listbox maps to the "value" member of the
hashtable?
I found that it is impossible to use a hashtable as a listbox datasource
directly (from trial and error) and tried DirectCast-ing to an arraylist
without any success. Before I spend anymore time in vain complex binding, I
thought I'd ask to see if anyone has figured a method of doing so.

D
Nov 21 '05 #1
5 7824
Hi Dave!

didn't test it but it seems ok
http://groups.google.com/groups?thre...40tkmsftngxa04

--
Best Regards
Yanick
"Dave" <dave(delete_this)@miraclecatDELETETHISTOO.com> a écrit dans le
message de news:OR**************@TK2MSFTNGP15.phx.gbl...
Hi all,
Is it possible to populate a listbox from a hashtable (complexbind) where
the ValueMember of the listbox maps to the "key" member of the hashtable AND the DisplayMember of the listbox maps to the "value" member of the
hashtable?
I found that it is impossible to use a hashtable as a listbox datasource
directly (from trial and error) and tried DirectCast-ing to an arraylist
without any success. Before I spend anymore time in vain complex binding, I thought I'd ask to see if anyone has figured a method of doing so.

D

Nov 21 '05 #2
Bummer, this only works in ASP.NET.

"Zoury" <yanick_lefebvre at hotmail dot com> wrote in message
news:Om**************@TK2MSFTNGP14.phx.gbl...
Hi Dave!

didn't test it but it seems ok
http://groups.google.com/groups?thre...40tkmsftngxa04
--
Best Regards
Yanick
"Dave" <dave(delete_this)@miraclecatDELETETHISTOO.com> a écrit dans le
message de news:OR**************@TK2MSFTNGP15.phx.gbl...
Hi all,
Is it possible to populate a listbox from a hashtable (complexbind) where the ValueMember of the listbox maps to the "key" member of the hashtable AND
the DisplayMember of the listbox maps to the "value" member of the
hashtable?
I found that it is impossible to use a hashtable as a listbox datasource
directly (from trial and error) and tried DirectCast-ing to an arraylist
without any success. Before I spend anymore time in vain complex

binding, I
thought I'd ask to see if anyone has figured a method of doing so.

D


Nov 21 '05 #3
oh sorry! i didn't pay much attention to the properties name from the
sample.

have you try this :
'***
Dim ht As Hashtable = New Hashtable(3)
ht.Add("item 1", 1)
ht.Add("item 2", 2)
ht.Add("item 3", 3)

ListBox1.DisplayMember = "key"
ListBox1.ValueMember = "value"

Dim entry As DictionaryEntry
For Each entry In ht
ListBox1.Items.Add(entry)
Next
'***

note that for some reason you must affect DisplayMember and ValueMember
properties before adding the items or the displayed item might not be
correct... (plus i'm not quite sure why it's not the other way around)

--
Best Regards
Yanick
"Dave" <dave(delete_this)@miraclecatDELETETHISTOO.com> a écrit dans le
message de news:eO**************@tk2msftngp13.phx.gbl...
Bummer, this only works in ASP.NET.

"Zoury" <yanick_lefebvre at hotmail dot com> wrote in message
news:Om**************@TK2MSFTNGP14.phx.gbl...
Hi Dave!

didn't test it but it seems ok

http://groups.google.com/groups?thre...40tkmsftngxa04

--
Best Regards
Yanick
"Dave" <dave(delete_this)@miraclecatDELETETHISTOO.com> a écrit dans le
message de news:OR**************@TK2MSFTNGP15.phx.gbl...
Hi all,
Is it possible to populate a listbox from a hashtable (complexbind) where the ValueMember of the listbox maps to the "key" member of the hashtable
AND
the DisplayMember of the listbox maps to the "value" member of the
hashtable?
I found that it is impossible to use a hashtable as a listbox

datasource directly (from trial and error) and tried DirectCast-ing to an arraylist without any success. Before I spend anymore time in vain complex

binding,
I
thought I'd ask to see if anyone has figured a method of doing so.

D



Nov 21 '05 #4
Thanks Zoury!

I learned something new: looping with the "DictionaryEntry" - This is
awesome and works faster than the datatable binding!
Forgive me for getting so excited over this, I am quite new to VB.Net!

"Zoury" <yanick_lefebvre at hotmail dot com> wrote in message
news:ej**************@TK2MSFTNGP15.phx.gbl...
oh sorry! i didn't pay much attention to the properties name from the
sample.

have you try this :
'***
Dim ht As Hashtable = New Hashtable(3)
ht.Add("item 1", 1)
ht.Add("item 2", 2)
ht.Add("item 3", 3)

ListBox1.DisplayMember = "key"
ListBox1.ValueMember = "value"

Dim entry As DictionaryEntry
For Each entry In ht
ListBox1.Items.Add(entry)
Next
'***

note that for some reason you must affect DisplayMember and ValueMember
properties before adding the items or the displayed item might not be
correct... (plus i'm not quite sure why it's not the other way around)

--
Best Regards
Yanick
"Dave" <dave(delete_this)@miraclecatDELETETHISTOO.com> a écrit dans le
message de news:eO**************@tk2msftngp13.phx.gbl...
Bummer, this only works in ASP.NET.

"Zoury" <yanick_lefebvre at hotmail dot com> wrote in message
news:Om**************@TK2MSFTNGP14.phx.gbl...
Hi Dave!

didn't test it but it seems ok

http://groups.google.com/groups?thre...40tkmsftngxa04

--
Best Regards
Yanick
"Dave" <dave(delete_this)@miraclecatDELETETHISTOO.com> a écrit dans le
message de news:OR**************@TK2MSFTNGP15.phx.gbl...
> Hi all,
> Is it possible to populate a listbox from a hashtable (complexbind)

where
> the ValueMember of the listbox maps to the "key" member of the hashtable AND
> the DisplayMember of the listbox maps to the "value" member of the
> hashtable?
> I found that it is impossible to use a hashtable as a listbox datasource > directly (from trial and error) and tried DirectCast-ing to an arraylist > without any success. Before I spend anymore time in vain complex

binding,
I
> thought I'd ask to see if anyone has figured a method of doing so.
>
> D
>
>



Nov 21 '05 #5
Thanks Zoury!

I learned something new: looping with the "DictionaryEntry" - This is
awesome and works faster than the datatable binding!
Forgive me for getting so excited over this, I am quite new to VB.Net!

"Zoury" <yanick_lefebvre at hotmail dot com> wrote in message
news:ej**************@TK2MSFTNGP15.phx.gbl...
oh sorry! i didn't pay much attention to the properties name from the
sample.

have you try this :
'***
Dim ht As Hashtable = New Hashtable(3)
ht.Add("item 1", 1)
ht.Add("item 2", 2)
ht.Add("item 3", 3)

ListBox1.DisplayMember = "key"
ListBox1.ValueMember = "value"

Dim entry As DictionaryEntry
For Each entry In ht
ListBox1.Items.Add(entry)
Next
'***

note that for some reason you must affect DisplayMember and ValueMember
properties before adding the items or the displayed item might not be
correct... (plus i'm not quite sure why it's not the other way around)

--
Best Regards
Yanick
"Dave" <dave(delete_this)@miraclecatDELETETHISTOO.com> a écrit dans le
message de news:eO**************@tk2msftngp13.phx.gbl...
Bummer, this only works in ASP.NET.

"Zoury" <yanick_lefebvre at hotmail dot com> wrote in message
news:Om**************@TK2MSFTNGP14.phx.gbl...
Hi Dave!

didn't test it but it seems ok

http://groups.google.com/groups?thre...40tkmsftngxa04

--
Best Regards
Yanick
"Dave" <dave(delete_this)@miraclecatDELETETHISTOO.com> a écrit dans le
message de news:OR**************@TK2MSFTNGP15.phx.gbl...
> Hi all,
> Is it possible to populate a listbox from a hashtable (complexbind)

where
> the ValueMember of the listbox maps to the "key" member of the hashtable AND
> the DisplayMember of the listbox maps to the "value" member of the
> hashtable?
> I found that it is impossible to use a hashtable as a listbox datasource > directly (from trial and error) and tried DirectCast-ing to an arraylist > without any success. Before I spend anymore time in vain complex

binding,
I
> thought I'd ask to see if anyone has figured a method of doing so.
>
> D
>
>



Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: James Goodman | last post by:
I have a listbox named sub1 on an asp page. I need to fill this list with values from a table. These are selected based upon the selection of a value/s in another listbox. It was suggested that I...
2
by: Wishing I was skiing mom | last post by:
Newbie to VB .NET. My solution contains an item maintenance screen, one of the fields on the screen is an item status, this field is defined as a listbox. The listbox item property contains a...
0
by: JH | last post by:
I have a Hashtable of strings to strings (i.e. names => values). This hashtable is populated dynamicly so it's contents are only known at runtime. I wish to populate a PropertyGrid control with...
3
by: Yul | last post by:
Hi, We are in the process of designing an ASP.NET app, where a user will enter some 'Customer ID' to be queried in the database. If the ID is valid, several stored procedures will be called to...
1
by: Devin Wood | last post by:
Hi, I have a page with a ListBox on it, and It's also have a some buttons to populate the ListBox by using JavaScript. I have no problem with populate the listbox using JavaScript. But when the...
5
by: Dave | last post by:
Hi All, I have a windows form that contains 2 listboxes and 2 buttons. The listbox on the right is populated by a database routine (This is the easy part). The listbox on the left is populated...
4
by: Joe Blow | last post by:
Folks, I have read all the posts about databases I could find and I think I need a little more help. I want to take all the items from a field in an access database and use them as list items in...
1
by: Chaihana Joe | last post by:
Hi I'm trying to populate a listbox as a value list in code (access 2003). Unfortunately I'm getting 'runtime error 2176 - the setting for this property is too long' somewhere around the 2000...
2
by: dbuchanan | last post by:
I intend to populate a listBox from the database for later use. (the intent for doing this is irrelevant to this questrion) The list box when hidden is never populated. The list box when visible...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.