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

Вниз

Как получить индексы выделенных элементов в ListBox е?   Найти похожие ветки 

 
vvp   (2006-02-19 05:34) [0]

Как получить индексы выделенных элементов в ListBox"е? Использую множественное выделение, соответственно curindex не подходит.


 
ECM ©   (2006-02-19 16:04) [1]

SelStart
      Start of selection (editbox - character position, listbox and combobox -
      index of [the first] selected item)
SelLength
      Length of selection (editbox - number of characters selected, multiline
      listbox - number of items selected)
Если элементы выделяются  не подряд - нужно смотреть в сторону

ListBox.Perform(LB_GETSELITEMS,...

An application sends an LB_GETSELITEMS message to fill a buffer with an array of integers that specify the item numbers of selected items in a multiple-selection list box.

Syntax

To send this message, call the SendMessage function as follows.
lResult = SendMessage(      // returns LRESULT in lResult     (HWND) hWndControl,      // handle to destination control     (UINT) LB_GETSELITEMS,      // message ID     (WPARAM) wParam,      // = (WPARAM) () wParam;    (LPARAM) lParam      // = (LPARAM) () lParam; );  
Parameters

wParam
Specifies the maximum number of selected items whose item numbers are to be placed in the buffer.
Microsoft® Windows® 95/Windows 98/Windows Millennium Edition (Windows Me) : The wParam parameter is limited to 16-bit values. This means list boxes cannot contain more than 32,767 items. Although the number of items is restricted, the total size in bytes of the items in a list box is limited only by available memory.

lParam
Pointer to a buffer large enough for the number of integers specified by the wParam parameter.
Return Value

The return value is the number of items placed in the buffer. If the list box is a single-selection list box, the return value is LB_ERR.


 
Vladimir Kladov   (2006-02-19 16:50) [2]

Намного проще
for i := 0 to LB1.Count-1 do
 if LB1.ItemSelected[ i ] then ...


 
ECM ©   (2006-02-19 19:21) [3]

А как же основной постулат КОЛ - минимум кода?  И по максимуму использовать то что встроено в систему?
:))

и вопрос был - "как получить индексы"?
Упрощенно - (допустим строк в листбоксе не более 1024):

var
 IdxArr: Array[0..1023] of Integer;
 SelCnt: Integer;
...
 SelCnt := ListBox1.Perform(LB_GETSELITEMS,1024,Integer(@IdxArr[0]));

вызовом одной API функции - получаем результат - первые SelCnt элементов массива будут содержать индексы выделенных элементов...
:))


 
Vladimir Kladov   (2006-02-19 22:02) [4]

вот как раз мой вариант - это и есть минимум кода. А то, что предложено, за минимум не сойдет, скорее за оптимизацию скорости.


 
ECM ©   (2006-02-20 12:06) [5]

Странно... сравнил две процедуры (D6 $0+}

procedure TForm1.Button1Click(Sender: PObj);
var
IdxArr: Array[0..1023] of Integer;
SelCnt: Integer;
begin
SelCnt := ListBox1.Perform(LB_GETSELITEMS,1024,Integer(@IdxArr[0]));
end;

procedure TForm1.Button2Click(Sender: PObj);
var
 i,j: Integer;
 IdxArr: Array[0..1023] of Integer;
begin
 j := 0;
 for i := 0 to ListBox1.Count-1 do begin
    if ListBox1.ItemSelected[ i ] then begin
      IdxArr[j] := i;
      Inc(j);
    end;
 end;
end;

Первая уменя имеет размер $28 (40 байт) вторая $42(66 байт)

???


 
Thaddy   (2006-02-20 14:04) [6]

Even more correct is calling LB_GETSELCOUNT first. To avoid missing one or more of 32767 possible selected items :)


 
ECM ©   (2006-02-20 14:51) [7]


> To avoid missing one or more of 32767 possible selected
> items :)


> ECM ©   (19.02.06 19:21) [3]


> Упрощенно - (допустим строк в листбоксе не более 1024):


 
Thaddy   (2006-02-20 15:06) [8]

Hm, back to babelfish.....
Russian is VERY difficult.



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

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

Наверх




Память: 0.48 MB
Время: 0.035 c
15-1164223584
KilkennyCat
2006-11-22 22:26
2006.12.10
Все-таки, что такое РГЗ?


15-1163696766
ArtemESC
2006-11-16 20:06
2006.12.10
Зачем нужна теория вероятности?


15-1163994143
Slider007
2006-11-20 06:42
2006.12.10
С днем рождения ! 20 ноября


2-1164478031
dreamse
2006-11-25 21:07
2006.12.10
Приветствую. Возникла проблема при создании компонента


3-1159721176
DimDim
2006-10-01 20:46
2006.12.10
Перекрестный запрос