【问题标题】:How to sort the items of a TcxImageComboBox by Description?如何按描述对 TcxImageComboBox 的项目进行排序?
【发布时间】:2011-11-18 16:43:12
【问题描述】:

我找到了一个很好的组件来实现 CaptionComboBox 的值列表:

Is there a ComboBox that has Items like a TcxRadioGroup?

唯一的问题是:它有一个 Sorted 属性,但这不起作用。

那么,如何对 TcxImageComboBox 的项进行排序?

【问题讨论】:

    标签: delphi sorting combobox devexpress delphi-2007


    【解决方案1】:

    快速而肮脏的方法,在大多数情况下应该可以正常工作:

    function CompareItems(AFirst: TcxImageComboBoxItem; ASecond: TcxImageComboBoxItem): Integer;
    begin
      Result := AnsiCompareText(AFirst.Description, ASecond.Description);
    end;
    
    procedure SortCxComboBoxItems(AItems: TcxImageComboBoxItems);
    var
      I    : Integer;
      J    : Integer;
      PMin : Integer;
    begin
      AItems.BeginUpdate;
      try
        // Selection Sort (http://en.wikipedia.org/wiki/Selection_sort)
        for I := 0 to AItems.Count - 1 do 
        begin
          PMin := I;
          for J := I + 1 to AItems.Count - 1 do 
          begin
            if CompareItems(AItems[J], AItems[PMin]) < 0 then begin
              PMin := J;
            end;
          end;
          if PMin <> I then 
          begin
            AItems[PMin].Index := I;
          end;
        end;
      finally
        AItems.EndUpdate;
      end;
    end;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 2020-12-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多