Recent

Author Topic: In TListBox how to multselect through code? [SOLVED]  (Read 811 times)

Renato Ricci

  • New Member
  • *
  • Posts: 22
    • Emissor NFe | Sistema Emissor NFe Web | Automação Comercial | Sat CFe NFe
In TListBox how to multselect through code? [SOLVED]
« on: August 10, 2023, 02:26:50 pm »
Hello friends, I tried the following code but it did not work. Any suggestions?

Code: Pascal  [Select][+][-]
  1. begin
  2.   ListBox1.Items.Clear;
  3.   ListBox1.Items.Add('AAAAAAA');
  4.   ListBox1.Items.Add('BBBB');
  5.   ListBox1.Items.Add('CCCCC');
  6.   ListBox1.Items.Add('DDDDD');
  7.   ListBox1.Items.Add('EEEEE');
  8.  
  9.   //The code bellow is not working
  10.   ListBox1.Selected[2];
  11.   ListBox1.Selected[3];
  12. end;

*Using Lazarus 2.2.6 x64

Thanks
Renato Ricci
« Last Edit: August 10, 2023, 02:52:03 pm by Renato Ricci »

Lulu

  • Sr. Member
  • ****
  • Posts: 363
Re: In TListBox how to multselect through code?
« Reply #1 on: August 10, 2023, 02:42:36 pm »
Hi, you have to  enable this feature on your ListBox1 with
Code: Pascal  [Select][+][-]
  1. ListBox1.MultiSelect := True;
then you can select the items with
Code: Pascal  [Select][+][-]
  1. ListBox1.Selected[2] := True;
  2. ListBox1.Selected[3] := True;

wishing you a nice life!
GitHub repositories https://github.com/Lulu04

Renato Ricci

  • New Member
  • *
  • Posts: 22
    • Emissor NFe | Sistema Emissor NFe Web | Automação Comercial | Sat CFe NFe
Re: In TListBox how to multselect through code?
« Reply #2 on: August 10, 2023, 02:42:50 pm »
I found the solution. I was missing the := true. Sorry

Code: Pascal  [Select][+][-]
  1. ListBox1.Selected[2] := True;
  2. ListBox1.Selected[3] := True;

Thanks
Renato

Renato Ricci

  • New Member
  • *
  • Posts: 22
    • Emissor NFe | Sistema Emissor NFe Web | Automação Comercial | Sat CFe NFe
Re: In TListBox how to multselect through code?
« Reply #3 on: August 10, 2023, 02:44:06 pm »
Hi, you have to  enable this feature on your ListBox1 with
Code: Pascal  [Select][+][-]
  1. ListBox1.MultiSelect := True;
then you can select the items with
Code: Pascal  [Select][+][-]
  1. ListBox1.Selected[2] := True;
  2. ListBox1.Selected[3] := True;

Thank You

 

TinyPortal © 2005-2018