Jump to content
Sign in to follow this  
Hugo Bendtner

TControlList - Jump to Selected

Recommended Posts

Having recently upgraded to Delphi 10.4, I'm experimenting with various controls and currently looking at the TControlList (without LiveBindings).

 

A few questions:

 

  1. Using TControlList with vertically aligned controls in a single column, when manually specifying the ItemIndex it jumps to the item, is there any way to make the scrollbars move so that the selected item is displayed at the top of the list? Currently if the item is off screen it scrolls to the item and the item is shown last.
  2. Is there any way to catch when the Selected item (ItemIndex) has changed? Or have I got to put in events for both onClick and onKeyPress etc?
  3. Is using ItemIndex the only way to find out what item has been selected? I assume I can never scroll through the list of items because they are all virtual?

Share this post


Link to post

I've tested with Delphi 10.4.2

 

1. A dirty trick would be first set the ItemIndex under the control you would like to select on the top:

 

  ControlList1.ItemIndex:=40+(ControlList1.Height div ControlList1.ItemHeight);
  ControlList1.ItemIndex:=40;
 

2. OnItemClicked is fired when the itemIndex changes (both from code or user navigation).

 

  

Share this post


Link to post

Hi, if you read French (or if you can translate it easily) I wrote some posts, sort of "Deep Diving in TControlList"  in  my blog starting from this one.

I am certain you will find some clues in this post

  • Like 1

Share this post


Link to post

Thanks, Serge_G (Google Translate does the trick!). I was fearful that I may have to extend the TControlList class, and that looks to be what you've done, because bizarrely the most useful functions are private.

Share this post


Link to post
2 minutes ago, Hugo Bendtner said:

I was fearful that I may have to extend the TControlList class, and that looks to be what you've done, because bizarrely the most useful functions are private

Yes, I was a little disappointed with all those needed private functions but was too lazy to suggest changes in the Quality portal :classic_blush:

Share this post


Link to post

Does anyone know if TControlLists can handle transparency? I would like to have a watermark underneath and whereas TPanels with clNone as their color are essentially transparent, the TControlList displays black. Messing around with ParentColor doesn't have desired results either.

Share this post


Link to post
18 hours ago, Hugo Bendtner said:

Does anyone know if TControlLists can handle transparency? I would like to have a watermark underneath and whereas TPanels with clNone as their color are essentially transparent, the TControlList displays black. Messing around with ParentColor doesn't have desired results either.

Tcontrollist inherits the ParentBackground property but does not publish it, it is protected. You can try to set it to true in code, using a cracker class:

 

type
  TControllistCracker = class(TControllist);
  
...

 TControllistcracker(Controllist1).Parentbackground := true;
  

Untested!

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×