Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2012.01.29;
Скачать: CL | DM;

Вниз

"Правильная " сортировка чисел в ListBox   Найти похожие ветки 

 
Laguna ©   (2011-10-21 16:39) [0]

Подскажите, есть ли  некий алгоритм сортировки чисел в Listbox чтобы они были представлены в правильном порядке. После установки Sort := True;, всеравно получается
...
102
20
92
...


 
Dennis I. Komarov ©   (2011-10-21 16:43) [1]

Напиши алгоритм сам и используй его...


 
Ega23 ©   (2011-10-21 16:43) [2]

Ты не числа, а строки сортируешь. Сортируй числи. Ну или 0 добавляй вперде.


 
Dennis I. Komarov ©   (2011-10-21 16:47) [3]

Пардон, я сперва ListView...


 
Юрий Зотов ©   (2011-10-21 16:48) [4]

ListBox содержит СТРОКИ, а не числа. Поэтому он и сортирует их как СТРОКИ, а не как числа.

А насчет "есть ли алгоритм" - конечно есть. Например, добавлять нули в начало каждой строки до тех пор, пока ее длина не станет равной длине самой длинной строки:
020
092
102


 
Медвежонок Пятачок ©   (2011-10-21 16:56) [5]

TStringList.CustomSort(MySortFunction)
+
ListBox1.Items.Assingn(SortedStringList);


 
Laguna ©   (2011-10-21 17:00) [6]

Это понятно что строки сортирую. Вот Нашел в нэте пример добавления пробелов до общей дины (http://forum.ixbt.com/post.cgi?id=print:26:32395)- не прокатило. С нулями думаю должно получиться, к тому же скорее всего числа и будут с лидирующими нулями.


 
DiamondShark ©   (2011-10-21 17:43) [7]

WM_COMPAREITEM Notification

--------------------------------------------------------------------------------

The system sends the WM_COMPAREITEM message to determine the relative position of a new item in the sorted list of an owner-drawn combo box or list box. Whenever the application adds a new item, the system sends this message to the owner of a combo box or list box created with the CBS_SORT or LBS_SORT style.

Syntax

WM_COMPAREITEM

   WPARAM wParam
   lpCompareItem = (LPCOMPAREITEMSTRUCT) lParam;
   
Parameters

wParam
Specifies the identifier of the control that sent the WM_COMPAREITEM message.
lpCompareItem
Pointer to a COMPAREITEMSTRUCT structure that contains the identifiers and application-supplied data for two items in the combo or list box.
Return Value

The return value indicates the relative position of the two items. It may be any of the values shown in the following table.

Value Meaning
-1 Item 1 precedes item 2 in the sorted order.
0 Items 1 and 2 are equivalent in the sorted order.
1 Item 1 follows item 2 in the sorted order.

Remarks

When the owner of an owner-drawn combo box or list box receives this message, the owner returns a value indicating which of the items specified by the COMPAREITEMSTRUCT structure will appear before the other. Typically, the system sends this message several times until it determines the exact position for the new item.

If a dialog box procedure handles this message, it should cast the desired return value to a BOOL and return the value directly. The DWL_MSGRESULT value set by the SetWindowLong function is ignored.


 
DiamondShark ©   (2011-10-21 17:50) [8]

Как вариант lbVirtual
и возвращать данные из внешнего хранилища в нужном порядке.



Страницы: 1 вся ветка

Текущий архив: 2012.01.29;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.009 c
2-1319204159
Alez
2011-10-21 17:35
2012.01.29
Не правильно работает код после перехода на Delphi XE2


15-1317751558
Dennis I. Komarov
2011-10-04 22:05
2012.01.29
D2006 и Win7


2-1319248809
inspiring
2011-10-22 06:00
2012.01.29
В TreeView из TTable.


2-1318774430
igorium
2011-10-16 18:13
2012.01.29
Как нарисовать на канве картинку, скруглив у неё края


1-1282384267
MSV
2010-08-21 13:51
2012.01.29
Двустрорнняя печать