Delphi 如何按说明对TcxImageComboBox的项进行排序?

Delphi 如何按说明对TcxImageComboBox的项进行排序?,delphi,sorting,combobox,devexpress,delphi-2007,Delphi,Sorting,Combobox,Devexpress,Delphi 2007,我找到了一个很好的组件来实现ComboBox的CaptionValue列表: 唯一的问题是:它有一个排序属性,但这不起作用 那么,如何对TcxImageComboBox中的项目进行排序呢?快速脏方法在大多数情况下都可以正常工作: function CompareItems(AFirst: TcxImageComboBoxItem; ASecond: TcxImageComboBoxItem): Integer; begin Result := AnsiCompareText(AFirst.

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

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


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

快速脏方法在大多数情况下都可以正常工作:

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;
函数CompareItems(第一个:TcximageComboxItem;第二个:TcximageComboxItem):整数;
开始
结果:=AnsiCompareText(第一个描述,第二个描述);
结束;
程序SortCxComboxItems(AItems:TcximageComboxItems);
变量
I:整数;
J:整数;
PMin:整数;
开始
AItems.BeginUpdate;
尝试
//选择排序(http://en.wikipedia.org/wiki/Selection_sort)
对于I:=0到AItems.Count-1 do
开始
PMin:=I;
对于J:=I+1到AItems.Count-1do
开始
如果CompareItems(AItems[J],AItems[PMin])小于0,则开始
PMin:=J;
结束;
结束;
如果我
开始
AItems[PMin]。索引:=I;
结束;
结束;
最后
AItems.EndUpdate;
结束;
结束;