473,490 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Sort Combobox Items

2 New Member
I have a combo box created using xaml. I bind the item source to a xml document.
Expand|Select|Wrap|Line Numbers
  1. <Items>
  2. <Item>
  3. <Name>David</Name>
  4. <Age>20</Age>
  5. </Item>
  6. <Item>
  7. <Name>Marcus</Name>
  8. <Age>25</Age>
  9. </Item>
  10. <Item>
  11. <Name>George</Name>
  12. <Age>25</Age>
  13. </Item>
  14. </Items>
  15.  
  16.  
  17. <ComboBox Name="cb1" ItemsSource="{Binding Source={StaticResource myList}, XPath=Items/Item}" DisplayMemberPath="Name"/>
  18.  
I would like to sort the combobox items so that the items are displayd in ascending order.

I manage to sort the above list by using SortDescription as below :

SortDescription sd = new SortDescription("Name", ListSortDirection.Ascending);

cb1.Items.SortDescriptions.Add(sd);

The combobox will display the items in the following order.

David
George
Marcus

Now, when I add a node to the xml document, I added CData to handle invalid characters. The xml document will be updated as below :
Expand|Select|Wrap|Line Numbers
  1. <Items>
  2. <Item>
  3. <Name>David</Name>
  4. <Age>20</Age>
  5. </Item>
  6. <Item>
  7. <Name>Marcus</Name>
  8. <Age>25</Age>
  9. </Item>
  10. <Item>
  11. <Name>George</Name>
  12. <Age>25</Age>
  13. </Item>
  14. <Item>
  15. <Name><![CDATA[Peter&#M]]></Name>
  16. <Age>25</Age>
  17. </Item>
  18. </Items>
When I do this, the sorting failed. The node with CData is always sorted to the top of the list.

Peter&#M
David
George
Marcus


Any idea what I can do to solve this problem?

Thanks.
Mar 18 '08 #1
1 14659
LoanB
62 New Member
Look at creating a Item Template for the combo box. Then add 2 columns one for Name and other for age. You ban then try to sort on the column you want.

I'm not 100% on this but it is where I would start looking.
Jun 18 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
7461
by: Wayne Wengert | last post by:
I am trying to populate a combobox with a lisy of items. I want the 1st item to be "Make a Selection" and the following items will be names from a table in my DB (See code below). When I run the...
1
6355
by: Rachel Suddeth | last post by:
When I put a ComboBox on a form, I can enter strings through the designer to fill Items collections. I have put a ComboBox in a UserControl, and exposed the the Items collections with the same...
5
25827
by: James P. | last post by:
Hello, For my new Windows application, all I want is to create an initial form to demo to the user to show them how it looks like with some data on it. So I figure the fastest way is to create...
6
7792
by: Sakharam Phapale | last post by:
Hi All, How to fill one ComboBox from other ComboBox control? 1) Only setting the reference does the trick but doesn't show items in control. If you see in immediate window, it shows...
4
32385
by: Peter | last post by:
C# .NET 1.1 How do I sort ComboBox in descending order? Thanks Peter
7
1893
by: samoore33 | last post by:
I am trying to dynamically add items to a listbox or combobox. The items add to either, but when I look through those items, there is nothing there. If I choose an item, it shows up. Not sure...
5
6776
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I want to create a customized ComboBox where the methods ComboBox.Items.Add and ComboBox.Items.Insert will behave thusly: -- If the item is not present, add it. -- If the item is present, set the...
4
6640
by: Jerad Rose | last post by:
I'm baffled by this -- is there not a typed object used for ComboBox Items? Best I can tell, all of the methods for ComboBox that accept an Item are of type Object. Why in the world is a...
15
2576
by: Academia | last post by:
I want a string of characters that will sort after all strings of Roman letters. Something that will display using a font like the one this note is written with. Is there such a thing? I...
0
7112
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
6974
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7146
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7183
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
7356
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
5448
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,...
1
4878
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...
0
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
277
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...

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.