Recent

Author Topic: TListView set selected item  (Read 22865 times)

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
TListView set selected item
« on: March 29, 2012, 04:17:56 pm »
Hello,

Is anyone having success in selecting the item of a TListView?

In my code I clear it and add some items and then try to set the selected item with:

  listCountries.ItemIndex := 0;

or

  listCountries.Selected := listCountries.Items[0];

But neither works =/

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: TListView set selected item
« Reply #1 on: March 29, 2012, 04:53:46 pm »
Both works here on Qt4: Lazarus 0.9.31 r35805M FPC 2.5.1 x86_64-linux-qt
I didn't test elsewhere.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: TListView set selected item
« Reply #2 on: March 29, 2012, 05:29:51 pm »
My test was in Win32

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: TListView set selected item
« Reply #3 on: March 29, 2012, 05:42:34 pm »
It works on GTK2-appearance as well.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Vingadero

  • New Member
  • *
  • Posts: 44
Re: TListView set selected item
« Reply #4 on: March 29, 2012, 07:21:44 pm »
Working here on Win64 too...

Pascaluvr

  • Full Member
  • ***
  • Posts: 216
Re: TListView set selected item
« Reply #5 on: March 29, 2012, 07:33:10 pm »
Do you mean that the item is not highlighted as selected?  Make sure you do SetFocus for the listview.
Windows 7, Lazarus 1.0.8, FPC 2.6.2, SQLite 3

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: TListView set selected item
« Reply #6 on: March 31, 2012, 12:04:59 am »
It is working without problem on the Carbon widgetset on Mac OS X.

The first line

listCountries.ItemIndex := 0;

works as is, the second line has to be formulated as

listCountries.Selected[0] := true;
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

PeterX

  • Sr. Member
  • ****
  • Posts: 404
Re: TListView set selected item
« Reply #7 on: February 10, 2016, 12:49:17 pm »
>>> Is anyone having success in selecting the item of a TListView?


I currently also work on SELECTING AN ITEM of a TListView.

- Lazarus 1.4.0
- Windows 7 64 Bit

But both types of call such as ..
Code: [Select]
listCountries.ItemIndex := i;
Code: [Select]
listCountries.Selected := listCountries.Items[i];
do not work for me. ...  >:D
« Last Edit: February 12, 2016, 10:06:07 am by PeterX »
usually using latest Lazarus release version with Windows 10

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TListView set selected item
« Reply #8 on: February 10, 2016, 01:40:30 pm »
But both types of call such as ..
- listCountries.ItemIndex := i;
- listCountries.Selected := listCountries.Items[ i];

do not work for me. ...  >:D
Hey - no need to get angry!

Both calls depend on the value of i which  must be >= 0 and < listCountries.Count.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: TListView set selected item
« Reply #9 on: February 10, 2016, 01:41:38 pm »
>>> Is anyone having success in selecting the item of a TListView?


I currently also work on SELECTING AN ITEM of a TListView.

- Lazarus 1.4.0
- Windows 7 64 Bit

But both types of call such as ..
- listCountries.ItemIndex := i;
- listCountries.Selected := listCountries.Items;

do not work for me. ...  >:D
works for me
Code: [Select]
  ListBox1.ItemIndex := SpinEdit2.Value;
or [code]
  ListBox1.Selected[SpinEdit1.Value] := True;
[/code]if you have multiselect set to true this one can be used to select multiple items.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

PeterX

  • Sr. Member
  • ****
  • Posts: 404
Re: TListView set selected item
« Reply #10 on: February 10, 2016, 11:54:26 pm »
Hm ...   ??!??!??!??!??!??!?


The combination of

      ListView.ItemIndex:= i;
      ListView.Selected;

did the job now.


BUT WHY ???????????????????????


For me this does NOT make any sense.
Can this be found in the documentation this way ?

Does this also work under DELPHI this curious way ?


Thanks,
Peter
usually using latest Lazarus release version with Windows 10

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TListView set selected item
« Reply #11 on: February 11, 2016, 12:16:09 am »
The combination of

      ListView.ItemIndex:= i;
      ListView.Selected;

did the job now.
This is certainly not correct, one of them is enough - see attached demo.

PeterX

  • Sr. Member
  • ****
  • Posts: 404
Re: TListView set selected item
« Reply #12 on: February 11, 2016, 02:18:35 pm »
Sorry, I'm on the job and can't test the demo code.


On (only)

   ListView.ItemIndex:= i;

nothing happens in my app .. :-(


I will try this evening, probably there's some buggy things to find in my code ;-)
usually using latest Lazarus release version with Windows 10

balazsszekely

  • Guest
Re: TListView set selected item
« Reply #13 on: February 11, 2016, 02:21:59 pm »
Quote
@PeterX
nothing happens in my app .. :-(
Because ListView is not focused, try to focus ListView with the SetFocus method. Alternatively you can set HideSelection property to False.

PeterX

  • Sr. Member
  • ****
  • Posts: 404
Re: TListView set selected item
« Reply #14 on: February 11, 2016, 04:25:11 pm »
From the old Delphi version of my program the

.SetFocus()

method call was already there.
But didn't work, doesn't work, I'm sorry.
usually using latest Lazarus release version with Windows 10

 

TinyPortal © 2005-2018