469,306 Members | 1,578 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

WPF equivalent of DropDownList?

I'm getting started with WPF & am converting a small asp.net app that uses a
couple of dropdownlists. They have the useful feature of holding a string
and also another (index) value in each item. ComboBox does not seem to have
this virtue. Suggestions?

Jun 27 '08 #1
7 21598
dropdownlist should work for you just fine. what issues are you having?

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $19.99
-------------------------------------------------------
"Jeremy" <je***********@ninprodata.comwrote in message
news:uJ**************@TK2MSFTNGP06.phx.gbl...
I'm getting started with WPF & am converting a small asp.net app that uses
a couple of dropdownlists. They have the useful feature of holding a
string and also another (index) value in each item. ComboBox does not
seem to have this virtue. Suggestions?
Jun 27 '08 #2
Alvin, so where on the toolbox is the ddl? Common goes from ComboBox to
Grid (no "D"). Controls goes from DocumentViewer to Ellipse. General is
empty.
"Alvin Bruney [ASP.NET MVP]" <vapor dan using hot male spam filterwrote in
message news:3F**********************************@microsof t.com...
dropdownlist should work for you just fine. what issues are you having?

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $19.99
-------------------------------------------------------
"Jeremy" <je***********@ninprodata.comwrote in message
news:uJ**************@TK2MSFTNGP06.phx.gbl...
>I'm getting started with WPF & am converting a small asp.net app that
uses a couple of dropdownlists. They have the useful feature of holding a
string and also another (index) value in each item. ComboBox does not
seem to have this virtue. Suggestions?
Jun 27 '08 #3
"Jeremy" <je***********@ninprodata.comwrote in message
news:uJ**************@TK2MSFTNGP06.phx.gbl...
I'm getting started with WPF & am converting a small asp.net app that uses
a couple of dropdownlists. They have the useful feature of holding a
string and also another (index) value in each item. ComboBox does not
seem to have this virtue. Suggestions?
In the WPF ComboBox the items can be any type of object, so one solution is
to define a class with two properties - the string and the index value - and
add instances of this class to your ComboBox (or bind a collection of
instances to its ItemsSource property).

Another option is to just add a string to the ComboBox and then use the
ComboBox.ItemContainerGenerator.ContainerFromItem( ) method (or
ContainerFromIndex) to give you the ComboBoxItem which WPF automatically
creates to actually hold the string you've just added. The ComboBoxItem has
a Tag property which you can use to hold your other value. However, I think
the first way is better.

Dr. WPF has written a very good set of blog posts on WPF ItemsControls (of
which ComboBox is one) - see
http://drwpf.com/blog/Home/tabid/36/...2/Default.aspx for example.

Chris Jobson
Jun 27 '08 #4
Chris, thanks for the pointer. Dr. WPF is a great site.

I've got this working, except for re-populating the itemsSource.

I have a list of objects which I use to populate the source. User picks one
and I populate some textboxes. When the user makes a change and saves it to
a database, I create a new List<T>, load it from the database and assign it
to itemsSource. I do the reload after save because I don't want to have to
detect whether the user added a new item or merely edited an existing one.

The problem is, after saving, the dropdown now has only 2 items showing, but
the actual itemsSource list has 4 items.

I figure there is some kind of reset that needs to be done, but haven't
found a method yet.

Any ideas?

Jeremy

Jun 27 '08 #5
"Jeremy" <je***********@ninprodata.comwrote in message
news:ef**************@TK2MSFTNGP03.phx.gbl...
Chris, thanks for the pointer. Dr. WPF is a great site.

I've got this working, except for re-populating the itemsSource.

I have a list of objects which I use to populate the source. User picks
one and I populate some textboxes. When the user makes a change and saves
it to a database, I create a new List<T>, load it from the database and
assign it to itemsSource. I do the reload after save because I don't want
to have to detect whether the user added a new item or merely edited an
existing one.

The problem is, after saving, the dropdown now has only 2 items showing,
but the actual itemsSource list has 4 items.

I figure there is some kind of reset that needs to be done, but haven't
found a method yet.

Any ideas?
That sounds very strange. Normally changing the ItemsSource is all that's
needed. A couple of ideas:
- I assume you first populated the list using the ItemsSource rather than
setting the Items property. If not I'm not sure what happens if both Items
and ItemsSource are set, but I'd suggest setting Items to null first.
- Is it definitely a NEW List<Tthat you are assigning to ItemsSource
(rather than re-using the same List<Tbut clearing and reloading the items
in the list)? If you are re-using the same List<Tobject then setting
ItemsSource to null and then back to the List should work.

If you haven't done so already, it might be worth looking at
ObservableCollection<Tinstead of List<T>, since that will automatically
notify any controls bound to it of changes to the items in the collection.

Good luck!
Chris
Jun 27 '08 #6
"Jeremy" <je***********@ninprodata.comwrote in message
news:ef**************@TK2MSFTNGP03.phx.gbl...
Chris, thanks for the pointer. Dr. WPF is a great site.

I've got this working, except for re-populating the itemsSource.

I have a list of objects which I use to populate the source. User picks
one and I populate some textboxes. When the user makes a change and saves
it to a database, I create a new List<T>, load it from the database and
assign it to itemsSource. I do the reload after save because I don't want
to have to detect whether the user added a new item or merely edited an
existing one.

The problem is, after saving, the dropdown now has only 2 items showing,
but the actual itemsSource list has 4 items.

I figure there is some kind of reset that needs to be done, but haven't
found a method yet.

Any ideas?
That sounds very strange. Normally changing the ItemsSource is all that's
needed. A couple of ideas:
- I assume you first populated the list using the ItemsSource rather than
setting the Items property. If not I'm not sure what happens if both Items
and ItemsSource are set, but I'd suggest setting Items to null first.
- Is it definitely a NEW List<Tthat you are assigning to ItemsSource
(rather than re-using the same List<Tbut clearing and reloading the items
in the list)? If you are re-using the same List<Tobject then setting
ItemsSource to null and then back to the List should work.

If you haven't done so already, it might be worth looking at
ObservableCollection<Tinstead of List<T>, since that will automatically
notify any controls bound to it of changes to the items in the collection.

Good luck!
Chris
Jun 27 '08 #7
"Jeremy" <je***********@ninprodata.comwrote in message
news:ef**************@TK2MSFTNGP03.phx.gbl...
Chris, thanks for the pointer. Dr. WPF is a great site.

I've got this working, except for re-populating the itemsSource.

I have a list of objects which I use to populate the source. User picks
one and I populate some textboxes. When the user makes a change and saves
it to a database, I create a new List<T>, load it from the database and
assign it to itemsSource. I do the reload after save because I don't want
to have to detect whether the user added a new item or merely edited an
existing one.

The problem is, after saving, the dropdown now has only 2 items showing,
but the actual itemsSource list has 4 items.

I figure there is some kind of reset that needs to be done, but haven't
found a method yet.

Any ideas?
That sounds very strange. Normally changing the ItemsSource is all that's
needed. A couple of ideas:
- I assume you first populated the list using the ItemsSource rather than
setting the Items property. If not I'm not sure what happens if both Items
and ItemsSource are set, but I'd suggest setting Items to null first.
- Is it definitely a NEW List<Tthat you are assigning to ItemsSource
(rather than re-using the same List<Tbut clearing and reloading the items
in the list)? If you are re-using the same List<Tobject then setting
ItemsSource to null and then back to the List should work.

If you haven't done so already, it might be worth looking at
ObservableCollection<Tinstead of List<T>, since that will automatically
notify any controls bound to it of changes to the items in the collection.

Good luck!
Chris
Jun 27 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Hai Nguyen | last post: by
2 posts views Thread by Hai Nguyen | last post: by
2 posts views Thread by Jennyfer J Barco | last post: by
reply views Thread by Chitty | last post: by
reply views Thread by Mutley | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.