简体   繁体   中英

vb.net using SortedDictionary as combobox datasource

I have a combobox which i am binding to a sortedDictionary list, so it displays in ascending order. My question is, I need to display "--Select--" as the first option. Is there any way to either: 1) add another item besides for the datasource or 2) add an unsorted item to the top of the sortedDictionary

any other ideas welcome as well :)

TIA

In the ascii sorting sequence, 11 characters ! " # $ % & ' ( ) + , come before -.

If it is not likely that your list of entries will start with any one of these characters, then adding your "-- Select --" item and resorting the list will result in "-- Select --" appearing at the top of the list.

A bit complicated solution would be writing a wrapper class which will put the --Select-- option at the beginning of your list. I'd like to know how exactly are you binding to the SortedDictionary though, I don't think that combo box accepts a dictionary for its data source.

Use the following code in a procedure that you use to create the sortedDictionary list. The main idea is to use a UNION the rest you can modify as appropriate

    SELECT
    '0' as yourCodeValue,
    '---Select ---' as yourValueDescription

    UNION 

    SELECT     
    yourCodeValue,
    yourValueDescription
    FROM  youTable
    ORDER By yourValueDescription

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM