Recent

Author Topic: selected items in listbox  (Read 8913 times)

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: selected items in listbox
« Reply #15 on: December 18, 2020, 08:58:39 pm »
In opposite to the TMemo the TListBox is robust and can used without problems >10 k items.

I don't know why folks are always bashing TMemo; I use it a lot for several purposes, including loading and editing huge amounts of text, without any appreciable problem. And 10k lines isn't all that much, is it? Even assuming long lines/paragraphs of 4k characters, that would be only around 40MiB; even my P4 w/ 512 MiB can deal very easily with that ...

Quote
PS.: Joan Jett, the Manalishi and John Lee Hooker - very good taste, man!
Thanks :D
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: selected items in listbox
« Reply #16 on: December 18, 2020, 09:41:57 pm »

I don't know why folks are always bashing TMemo;



Hi Lucamar!

Painfull experience with Delphi 1, 2, 3, ...

Retried it with the early Lazarus versions:
The same rubbish. Delphi compatible.
Now I don't use it anymore.

Winni


Handoko

  • Hero Member
  • *****
  • Posts: 5545
  • My goal: build my own game engine using Lazarus
Re: selected items in listbox
« Reply #17 on: December 19, 2020, 03:14:22 am »
I don't think 10k items really stresses its limits ...

TListBox is robust and can used without problems >10 k items.

Sorry, I didn't explained clearly in my previous post.

How can you select an item from a list of 10.000 items? Do you press page down key or click the scroll down button hundred times? Maybe what OP really need is a case-insensitive searchable listbox. I remember there were some code examples posted on the forum or the OP can simply download and use mine.

For example if user want to select Cairo form a list of city names, if the user type letter 'c', the list will be filtered to show only: Auckland, Barcelona, Cairo, Cape Town, Chicago, Monaco, San Francisco. And if the user then press 'a', the list will be filtered to have Cairo and Cape Town only.
« Last Edit: December 19, 2020, 07:16:30 am by Handoko »

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: selected items in listbox
« Reply #18 on: December 19, 2020, 07:06:47 am »
How can you select an item from a list of 10.000 items? Do you press page down key or click the scroll down button hundred times? Maybe what OP really need is a searchable listbox. I remember there were some code examples posted on the forum or the OP can simply download and use mine.

Well, yes, that's a "small" user-experience problem ... and a possible solution. But he already said that the 10k was just a stress-test ... which is to what we were responding.

Quote
For example if user want to select Cairo form a list of city names, if the type letter 'c', the list will be filtered to show only: Auckland, Barcelona, Cairo, Cape Town, Chicago, Monaco, San Francisco. And if the user then press 'a', the list will be filtered to have Cairo only.

There at the end, it should rather be Cairo and Cape Town, shouldn't it? ;D
« Last Edit: December 19, 2020, 07:09:53 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Handoko

  • Hero Member
  • *****
  • Posts: 5545
  • My goal: build my own game engine using Lazarus
Re: selected items in listbox
« Reply #19 on: December 19, 2020, 07:10:18 am »
Quote
For example if user want to select Cairo form a list of city names, if the type letter 'c', the list will be filtered to show only: Auckland, Barcelona, Cairo, Cape Town, Chicago, Monaco, San Francisco. And if the user then press 'a', the list will be filtered to have Cairo only.

There at the end, it should rather be Cairo and Cape Town, wouldn't it? ;D

Oops, my mistake.  :-[

Paolo

  • Hero Member
  • *****
  • Posts: 718
Re: selected items in listbox
« Reply #20 on: December 19, 2020, 08:18:43 am »
Quote
How can you select an item from a list of 10.000 items? Do you press page down key or click the scroll down button hundred times?
Just use the vertical scrollbar, obviously the list must be sorted.

Handoko

  • Hero Member
  • *****
  • Posts: 5545
  • My goal: build my own game engine using Lazarus
Re: selected items in listbox
« Reply #21 on: December 19, 2020, 09:42:38 am »
Quote
How can you select an item from a list of 10.000 items? Do you press page down key or click the scroll down button hundred times?
Just use the vertical scrollbar, obviously the list must be sorted.

That doesn't work well on some cases.

For example:

You are a chief security that work in a big hotel. You got the information that someone called Ben stayed in the hotel last month, and he is a suspect of a future terrorism. So you login to the computer system and run the visitor database program to print the information collected on their check-in. You found several names: Ben Ten (the kid of the Cartoon Network!), Charles Benny, Madison Bennett, Richard Ben, William Bentley.

Then you go to the IT department and complain that simply finding the guests who has ben in their names was tiresome. Because the software showed you a list of thousand names and you had to manually scroll the list to find them.

Writing code that works correctly isn't hard. Writing software that has good UI/UXD is not easy.
 ;D
« Last Edit: December 19, 2020, 11:35:45 am by Handoko »

dsiders

  • Hero Member
  • *****
  • Posts: 1633
Re: selected items in listbox
« Reply #22 on: December 19, 2020, 05:15:39 pm »
This is what I exacltly do. So, no alternatives, no list of selected item.

Thank you.

TCustomListBox.GetSelectedText is an alternative, but possibly not the format you're looking for.

Paolo

  • Hero Member
  • *****
  • Posts: 718
Re: selected items in listbox
« Reply #23 on: December 19, 2020, 05:32:34 pm »
thanks, intersting...

however what I need for my purpose it is the list-of-index-of-selected-items, also GetSelectedText goes trough the whole list, the real altrenative is to manage such list in a custom way, eg as Handoko did.

jamie

  • Hero Member
  • *****
  • Posts: 7768
Re: selected items in listbox
« Reply #24 on: December 19, 2020, 09:49:12 pm »
The Window Interface API for the list does provide a feature where you can define an array of integers of all selected items. They represent the indexes to each line.
I don't see such member function in the Tlist box so it most likely it isn't implemented as a cross platform solution..

but in any case is that was you're looking for, an array of indexes instead of the string bulk ?
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 7768
Re: selected items in listbox
« Reply #25 on: December 19, 2020, 10:02:41 pm »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   A:array of smallInt; {16 bit size}
  4. begin
  5.   SetLength(A, ListBox1.Count);
  6.   Caption := Sendmessage(ListBox1.Handle , LB_GETSELITEMS, 1000, PtrUint(@A[0])).Tostring;
  7.   //A array now holds the Index list of all selected items.
  8. end;
  9.                        
  10.  


Include the windows unit

P.S.

  This is limited up to 32767 entries since it's using a 16 bit size but that is a lot of entries each having untold line lengths.

« Last Edit: December 19, 2020, 10:08:17 pm by jamie »
The only true wisdom is knowing you know nothing

Paolo

  • Hero Member
  • *****
  • Posts: 718
Re: selected items in listbox
« Reply #26 on: December 19, 2020, 10:12:27 pm »
Quote
but in any case is that was you're looking for, an array of indexes instead of the string bulk ?

Yes. Something that allows a code like this

Code: Pascal  [Select][+][-]
  1. for i:=0 to listbox.selcount-1 do begin
  2.   //do something... := listbox.selecteditem[i]
  3. end
  4.  

But just to clarify, I can survive with the code below

 
Code: Pascal  [Select][+][-]
  1. for i:=0 to listbox.count-1 do begin
  2.   If listbox.selected[i] then
  3.      //do something... := listbox.item[i]
  4. end
  5.  

Paolo

  • Hero Member
  • *****
  • Posts: 718
Re: selected items in listbox
« Reply #27 on: December 19, 2020, 10:15:05 pm »
@jamie

Thanks

 

TinyPortal © 2005-2018