473,605 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 22163
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.comw rote in message
news:uJ******** ******@TK2MSFTN GP06.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******** *************** ***********@mic rosoft.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.comw rote in message
news:uJ******** ******@TK2MSFTN GP06.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.comw rote in message
news:uJ******** ******@TK2MSFTN GP06.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.ItemCo ntainerGenerato r.ContainerFrom Item() method (or
ContainerFromIn dex) 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.comw rote in message
news:ef******** ******@TK2MSFTN GP03.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
ObservableColle ction<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.comw rote in message
news:ef******** ******@TK2MSFTN GP03.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
ObservableColle ction<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.comw rote in message
news:ef******** ******@TK2MSFTN GP03.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
ObservableColle ction<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2774
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option Description"></asp:BoundColumn> <asp:TemplateColumn runat="server" HeaderText="Id Type Option" "> <itemtemplate> <asp:label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "TypeOption") %>' /> <asp:label runat="server" ID="LlbTypeOption" Visible=False...
2
2798
by: Hai Nguyen | last post by:
Hi everyone I'm developing an wep application, I got stuck into a problem. My database has a table which has 2 fields Table1 X Y A Apple B Banana C Cat
2
16989
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of the columns of the data grid contains a DropDownlist. I managed to create this datagrid control as follows.
2
1076
by: Hai Nguyen | last post by:
Hi everyone I'm developing an wep application, I got stuck into a problem. My database has a table which has 2 fields Table1 X Y A Apple B Banana C Cat
2
344
by: Jennyfer J Barco | last post by:
Hello is there a way to create a dropdownlist inside a <input type='dropdownlist'> or there is an equivalent to create other than <asp:DropDownList id="drop1" runat="server"> . I need this because it's a dynamic page and I need to create the dropdown control in any position needed depending on what the user selected, so I'm creating this dropdownlist at run time. Thanks in advance Jennyfer
0
820
by: Chitty | last post by:
Hi All, Hope someone can help me out on this one, it's been driving me around the bend. In essence I'm trying to replicate a custom class hierachy relating to my problem domain database. The actual domain I'm working on is irrelevant, so I've been playing with two noddy classes; Person and Pet (the full code can be found here: <http://www.junge.f9.co.uk/code/CustomClassDDL.zip>).
0
1245
by: Mutley | last post by:
I am finding an issue with the current DropDownList and ListBox ASP.NET Web Controls. I had a system set up for Arabic and a string that I put into a drop down contained a number. The letters were being displayed in Arabic but the numbers were appearing as 1,2,3, etc. In other parts of my app, the Arabic equivalent to these numerals would appear as expected. I found an MSDN link to the following web page that mentioned there was an issue...
1
4918
by: Brett | last post by:
I have a DropDownList in an ASP.NET web form that is populated with items from a lookup table by binding that DropDownList to a SqlDataSource. However, the items in the lookup table can change over time. The problem is that when an item has been removed from the lookup table, and a user wants to retrieve a record that used the deleted item, the following error occurs: 'ddlAssignedTo' has a SelectedValue which is invalid because it...
0
1933
by: asmx126453 | last post by:
Hey mensen I am having some big troubles here i tryd solving it myself with internet for 2 days but i kind fix it. Its about this i have a DotNet project that alrydi is online and working for almost everything. but it whas made in Visual Studio 7 and i converted it to 2005. in version 7 it works almost perfect but in 2005 i am having some errors. becase all the code i am using is very long i am trying to post the nesecery code only if...
0
8007
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8423
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8076
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8290
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6749
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5446
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3960
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1274
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.