473,770 Members | 4,029 Online
Bytes | Software Development & Data Engineering Community
+ 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", ListSortDirecti on.Ascending);

cb1.Items.SortD escriptions.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 14708
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
7495
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 project, the combox box initially displays an empty selection. When I click on the drop down arrow I see the "Make a Selection" followed by the other choices. How can I move everything up so that the "Make a Selection" is the default value in...
1
6396
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 type... public class ControlWithComboBox : MyControls.BaseControl, IDataEntryControl { ... protected System.Windows.Forms.ComboBox comboBox; ... public ComboBox.ObjectCollection Items
5
25842
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 some comboBox-es to show some data on them manually entered in the code without connecting to the database yet. It should be simple but somehow I can't make it work. First, I drag a comboBox from the ToolBox to the form. Then,
6
7811
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 the item count correctly
4
32422
by: Peter | last post by:
C# .NET 1.1 How do I sort ComboBox in descending order? Thanks Peter
7
1911
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 why, but the items are not visible in the listbox or combobox until one of the items has been chosen. This of course is not good, since someone can not see the items they need to choose from. Any help would be appreciated.
5
6790
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 selected index to the item (without adding a duplicate). I know the basics of inheriting from user controls, so if this was merely overriding a method of ComboBox I could do it. But how does one go about overriding a method of the Items...
4
6666
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 common/standard .NET control accepting an Object as a parameter type? In Web Forms, there is a ListItem object that can be passed in to add/retrieve objects from a DropDownItems collection. I searched Google groups, and all the solutions I'm finding...
15
2607
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 tried using a string starting with { because in ASCII it comes after the letters but that sorts before the letters.
0
9602
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
9439
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10237
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9882
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
8905
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
7431
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
6690
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
5326
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.