【问题标题】:C# ComboBox Sorting IssueC# 组合框排序问题
【发布时间】:2016-12-26 22:34:42
【问题描述】:

我对组合框排序有疑问。 组合框正确排序数字(一半) 当第十位小于该位时,两位数在一位数之前,我的意思是:

1

11

12

2

如何更改组合框的顺序,使其看起来像:

1

2

11

12

A Combobox image

【问题讨论】:

  • 请发布组合框填充代码
  • 您使用的是字符串而不是 int
  • 值的数据类型是什么?我认为你的情况是字符串
  • 这是你想要的答案--> answer
  • 我的代码(图片):prntscr.com/do1vrh 我在数据库中使用的是 int 而不是字符串

标签: c# sorting


【解决方案1】:

Kfir,试试这种方式,使用datasource,不要手动填充item:

    private readonly List<int> _list = new List<int>();
    private BindingList<int> _bList;
    private readonly BindingSource _bSource = new BindingSource();

    private void Form1_Load(object sender, EventArgs e)
    {
        _list.Add(23);
        _list.Add(2);
        _list.Add(5);
        _list.Add(12);
        _list.Add(14);
        _list.Add(8);
        _list.Add(9);
        _list.Add(15);
        _list.Add(21);
        _list.Add(22);
        _list.Add(1);

        _bList = new BindingList<int>(_list);
        _bSource.DataSource = _bList;
        comboBox2.DataSource = _bSource;
        _list.Sort();
        _bList.ResetBindings();

【讨论】:

  • 谢谢,但我需要从 Access 获取值
  • 好的。您可以从数据库中填写“List _list”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-22
  • 2010-11-25
  • 2011-02-09
  • 1970-01-01
  • 2021-11-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多