vb.net 使用 SortedDictionary 作为组合框数据源

发布于 2024-08-26 13:26:24 字数 160 浏览 5 评论 0原文

我有一个组合框,我将其绑定到排序字典列表,因此它按升序显示。我的问题是,我需要显示“--Select--”作为第一个选项。有没有办法: 1)除了数据源之外添加另一个项目 或者 2)将未排序的项目添加到sortedDictionary的顶部,

也欢迎任何其他想法:)

TIA

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无力看清 2024-09-02 13:26:24

在ascii排序序列中,11个字符! " # $ % & ' ( ) + ,位于 - 之前。

如果您的条目列表不太可能以这些字符之一开头,则添加您的“-- Select --”项目并重新排序列表将结果“--选择--”出现在列表顶部。

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.

眼泪淡了忧伤 2024-09-02 13:26:24

一个有点复杂的解决方案是编写一个包装类,它将 --Select-- 选项放在列表的开头。我想知道您到底如何绑定到 SortedDictionary,但我不认为组合框接受字典作为其数据源。

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.

比忠 2024-09-02 13:26:24

在用于创建排序字典列表的过程中使用以下代码。主要思想是使用UNION,其余的你可以适当修改

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

    UNION 

    SELECT     
    yourCodeValue,
    yourValueDescription
    FROM  youTable
    ORDER By yourValueDescription

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文