Recent

Author Topic: HowTo default the 1st entry as selected in a TreeView  (Read 668 times)

roger T

  • New Member
  • *
  • Posts: 14
HowTo default the 1st entry as selected in a TreeView
« on: June 25, 2024, 08:15:28 am »
Subject says most of it. When I click on an empty area of a treeview I get a SIGSEGV but do not if an item is already selected.
How do I set an entry as selected when the treeview is created

Cheers
Roger

TRon

  • Hero Member
  • *****
  • Posts: 3631
Re: HowTo default the 1st entry as selected in a TreeView
« Reply #1 on: June 25, 2024, 08:23:37 am »
Depending on your use case you could use  selected or select
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

cdbc

  • Hero Member
  • *****
  • Posts: 1663
    • http://www.cdbc.dk
Re: HowTo default the 1st entry as selected in a TreeView
« Reply #2 on: June 25, 2024, 08:46:15 am »
Hi
First the easy one:
Code: Pascal  [Select][+][-]
  1. TreeView1.Items[0].Selected:= true; // root node selected
Second: Do you by any chance, have an 'OnClick' event-handler for the treeview? Then you need to test for nil in that handler, explicitly for when user clicks /outside/ of nodes, but generally it's good practice with treeviews.
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

roger T

  • New Member
  • *
  • Posts: 14
Re: HowTo default the 1st entry as selected in a TreeView
« Reply #3 on: June 25, 2024, 08:48:06 am »
Brilliant. Thank you kindly
Cheers
Roger

 

TinyPortal © 2005-2018