2016-07-24 3 views
1

나는, 나는 다음과 같은 코드콤보 박스 내에서 항목을 정렬하는 방법은 무엇입니까?

combobox1.Items.BeginUpdate; 
try 
    combobox1.Sorted := True; 
    combobox1.Items.Add('0'); 
    combobox1.Items.Add('2'); 
    combobox1.Items.Add('1'); 
    combobox1.Items.Add('3'); 
    combobox1.Items.Add('5'); 
    combobox1.Items.Add('4'); 
finally 
    combobox1.Items.EndUpdate; 
end; 

나는 등 0,1,2,3,4,5 이러한 숫자를 정렬 할 ... 그리고에서와 같이, 일부 번호를 추가 콤보 상자가 combobox 안에 있습니다.

Sorted 속성을 활성화했지만 항목이 정렬되지 않았습니다.

숫자가 combobox 인 항목을 어떻게 정렬 할 수 있습니까?

는이 코드로 사실상 TList에서 combobox에서 항목을로드 :

var 
    J : integer; 
    themes : Tthemes; 
begin 
    ComboBox1.Items.BeginUpdate; 
    try 
    ComboBox1.Sorted := True; 
    for J := 0 to listitems.Count - 1 do 
    begin 
     themes := listitems.Items[J]; 
     ComboBox1.Items.Add(themes.designid); 
    end; 
    finally 
    ComboBox1.Items.EndUpdate; 
    end; 

    ComboBox1.ItemIndex := 0; 
+0

나는 코드를 시도하고 그 결과를 정렬됩니다! XE7 및 Vcl 프로젝트를 가정합니다. –

+0

이상한 나는 동일한 코드를 수행하고 결과는 dll 프로젝트에서이 코드를 사용하여 정렬 된 iam없이 추가 한 것과 동일합니다. –

+0

dll 인 프로젝트가 어떤 영향을 미칠 수 있는지 상상할 수 없습니다. 그러나 경우에 따라 새로운 vcl 양식 프로젝트를 사용해보십시오. 폼에 콤보 상자와 단추를 놓습니다. OnClick 이벤트 복사 버튼에서 위의 코드를 붙여 넣습니다. 다른 디자인 타임 설정은 없습니다. –

답변

0

이 시도 :

combobox1.Sorted := False; 
    combobox1.Items.Add('0'); 
    combobox1.Items.Add('2'); 
    combobox1.Items.Add('1'); 
    combobox1.Items.Add('3'); 
    combobox1.Items.Add('5'); 
    combobox1.Items.Add('4'); 
    combobox1.Sorted := True; 
관련 문제