473,322 Members | 1,401 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,322 software developers and data experts.

Combobox

I thought I could create a "ListViewItem" and then bind that item to a
combox box, but perhaps that is was with an ASP.Net control. When I create
a listViewItem and bind it to a combo box, it does bind, but what show up
is something like ListViewItem{MyField}.

So if I have a hastable, what mechanism would I use to create a bindable
object such that I can define the "ValueMember" and "DisplayMember"?

Thanks in advance for your assistance!!!!!!!!!
Nov 15 '05 #1
2 6914
Complex DataBinding accepts as a data source either an IList or an
IListSource. So you can't bind a HashTable directly to a ComboBox.

The following code shows a work-around:
Dim myHashTable as new System.Collections.Hashtable()

myHashTable("GA") = "Georgia"
myHashTable("FL") = "Florida"
myHashTable("AL") = "Alabama"

For each Item in myHashTable
Dim newListItem as new ListItem()
newListItem.Text = Item.Value
newListItem.Value = Item.Key
DropDownList1.Items.Add(newListItem)
Next

http://www.devcity.net/net/article.a...spnet_dropdown

--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan
"Jim Heavey" <Ji*******@nospam.com> schreef in bericht
news:Xn*********************************@207.46.24 8.16...
I thought I could create a "ListViewItem" and then bind that item to a
combox box, but perhaps that is was with an ASP.Net control. When I create a listViewItem and bind it to a combo box, it does bind, but what show up
is something like ListViewItem{MyField}.

So if I have a hastable, what mechanism would I use to create a bindable
object such that I can define the "ValueMember" and "DisplayMember"?

Thanks in advance for your assistance!!!!!!!!!

Nov 15 '05 #2
Jim,

The dropdown control can take a ListViewItem object as a parameter to the
Items.Add() method but it only uses the Text property when adding it. The
ListViewItem is only full used by ListBox class.

I'm not sure why you are trying to use binding instead of a loop with calls
the DropDownList.Add() method but, keep in mind the nature of binding. All
objects can be bound to most controls, however some controls simply call the
ToString() method if the object does not support the IEnumarable interface.

Simply put the most common use of binding is to set the DataSource property
to a collection or array. Then set the other Data...Field propertys with
the field names. Then when the DataBind() method is called the control loops
through the DataSource object using the IEnumerable interface and uses
reflection to load the control with the Data Fields specified.
Note: Binding is always slower than Adds due to the use of reflection.

With that said, since a Hashtable class supports the IEnumerable interface
you can do the following: Set the DropDownList.DataSource property to the
Hashtable object, Set the DropDownList.DataTextField property to "Value" as
in the IDictionaryEnumerator.Value, Set the DropDownList.DataValueField
property to "Key" as in the IDictionaryEnumerator.Key.

One thing of note is that when loading the Value object, from the Hashtable,
will have it's ToString() method called. This is why when you bound the
ListViewItem, you saw the text you did.

For more information on C# Controls look at the MSDN help and look for the
"DropDownList class" and the "Hashtable class" in the index. Each method
and property are described in detail.

A little long winded but hope this helps.
--
Glen Jones MCSD

"Jim Heavey" <Ji*******@nospam.com> wrote in message
news:Xn*********************************@207.46.24 8.16...
I thought I could create a "ListViewItem" and then bind that item to a
combox box, but perhaps that is was with an ASP.Net control. When I create a listViewItem and bind it to a combo box, it does bind, but what show up
is something like ListViewItem{MyField}.

So if I have a hastable, what mechanism would I use to create a bindable
object such that I can define the "ValueMember" and "DisplayMember"?

Thanks in advance for your assistance!!!!!!!!!

Nov 15 '05 #3

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

Similar topics

13
by: Mr. B | last post by:
Here's the situation... You've a combobox with Items already added. Say they look like this (or even lines of text): 10-00-232 10-00-256 10-01-006 10-01-213 10-02-200
7
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
1
by: anonymous | last post by:
I've been trying to put a them, please help me out. Here's the major parts of my code: public Form1() { DataSet myDataSet = new DataSet("myDataSet"); DataTable testTable = new...
3
by: TT (Tom Tempelaere) | last post by:
Hay there, I'm writing my own DataGridComboBoxColumn because .NET 1.1 does not have one (I hope .NET 2.0 supplies one). I based it on this article:...
2
by: Don | last post by:
I've looked high and low for some code that will allow me to have a combobox with a flat borderstyle. I found a few examples, but nothing that was really usable for me. I had the following...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
6
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox...
1
by: polocar | last post by:
Ciao a tutti, leggendo qua e lŕ per il forum ho scoperto che non sono l'unico ad avere questo problema. Se si inserisce un controllo ComboBox in un form di C#, non č possibile impostare la sua...
5
by: Rich | last post by:
Hello, I have a search application to search data in tables in a database (3 sql server tables). I populate 2 comboboxes with with data from each table. One combobox will contain unique...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.