Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "KOL";
Текущий архив: 2006.12.10;
Скачать: [xml.tar.bz2];

Вниз

Как получить индексы выделенных элементов в 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 вся ветка

Форум: "KOL";
Текущий архив: 2006.12.10;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.47 MB
Время: 0.037 c
15-1163696766
ArtemESC
2006-11-16 20:06
2006.12.10
Зачем нужна теория вероятности?


15-1163777445
Rbn
2006-11-17 18:30
2006.12.10
Delphi 7


2-1163780397
Calibr
2006-11-17 19:19
2006.12.10
График


11-1140415603
LAutour
2006-02-20 09:06
2006.12.10
Нужно передать Items из KOLListBox параметром в процедуру.


15-1164126004
Reaktor
2006-11-21 19:20
2006.12.10
Прпал пуск в ХР





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский