Recent

Author Topic: Draw one item highlighted in TListview regardless of focus  (Read 2494 times)

RedOctober

  • Sr. Member
  • ****
  • Posts: 452
Draw one item highlighted in TListview regardless of focus
« on: March 26, 2019, 03:24:28 pm »
Platform: Lazarus 1.8.2, FPC 3.0.4, Windows Server 2016

In a page control, I have several tabs of TListview each with about 200 items.  My user will select a single item in each of the TListView (which turns it highlight blue background) and then tab to the other list views.  The problem is that when the user returns to the previous tab(s), they need to be able to easily see what they had selected. I want it highlighted in blue at all times whether the TListView has focus or not.  If the user looks very carefully, they can see that the selected item is still selected, but it's background color is a very dim gray, very hard to see.  I need that selected item to stay with a background of highlight blue at all times, even when the user clicks away and comes back, even if the user opens another window and moves it out of the way of the TListView, the selcted item should still be highlight blue.  How do I accomplish this?  (All my attempts to do this in OnDrawEvent or CustomDraw events have failed.)

Thanks for any help you can provide.

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Draw one item highlighted in TListview regardless of focus
« Reply #1 on: March 26, 2019, 04:01:02 pm »
Apologies - I'm away from an IDE right now, so can't give exact steps.  Somewhere on the TListView there is a HideSelection option - either on the TListView, or in TListView.Options.  Ensure this is set to false.
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

RedOctober

  • Sr. Member
  • ****
  • Posts: 452
Re: Draw one item highlighted in TListview regardless of focus
« Reply #2 on: March 26, 2019, 06:06:09 pm »
Hi Mike, thanks for the suggestion.  I should have mentioned that the HideSelection is set to false.  That actually is what enables the selected item to have a background of light gray.  If set it to True, the selected item is not indicated in any way if the TListView is not in focus (active control), just a plain white background.  I think I need to have a code snippet put in the OnItemDraw or something to change the gray background on the selected item to blue highlight on the selected item, even when the TListView does not have focus. 

Still needed some extra help on this.

sstvmaster

  • Sr. Member
  • ****
  • Posts: 299
Re: Draw one item highlighted in TListview regardless of focus
« Reply #3 on: March 26, 2019, 09:43:14 pm »
you can use this.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.PageControl1Change(Sender: TObject);
  2. begin
  3.   if PageControl1.ActivePage.IsVisible then PageControl1.ActivePage.SetFocus;
  4. end;
greetings Maik

Windows 10,
- Lazarus 2.2.6 (stable) + fpc 3.2.2 (stable)
- Lazarus 2.2.7 (fixes) + fpc 3.3.1 (main/trunk)

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Draw one item highlighted in TListview regardless of focus
« Reply #4 on: March 26, 2019, 10:52:36 pm »
I think he is looking to make entries look highlighted / Selected when they are not the selected index

For that, they need to use the OwnerDraw options I think.
The only true wisdom is knowing you know nothing

sstvmaster

  • Sr. Member
  • ****
  • Posts: 299
Re: Draw one item highlighted in TListview regardless of focus
« Reply #5 on: March 27, 2019, 12:11:34 am »
see attachment.

Select an entry on each tab in Listview element and switch checkbox
« Last Edit: March 27, 2019, 12:13:50 am by sstvmaster »
greetings Maik

Windows 10,
- Lazarus 2.2.6 (stable) + fpc 3.2.2 (stable)
- Lazarus 2.2.7 (fixes) + fpc 3.3.1 (main/trunk)

RedOctober

  • Sr. Member
  • ****
  • Posts: 452
Re: Draw one item highlighted in TListview regardless of focus
« Reply #6 on: March 27, 2019, 12:42:03 am »
Hi sstvmaster,

I have tried playing around with .Focus for a few hours.  Your suggestion partially helps if I don't have another control on the form that I need to set focus to, like a little search box for example.  Here's the problem, if I spawn another form from the window with my TListView on it, the form goes "Deactivated", and when I return to that spawning form it becomes Activated.   Two problems:

- I need the selected TListView item to be in a color of my choice (maybe highlight blue or green) even when the form is deactivated or activated and the TListView is not the focused control.
- When the form regains Active status from being in a Deactivated state, the selected item shd again, be in the color that I choose.  I only have one selected item (Multi-select is False);

What I need in TListView already exists in TDBGrid, with the "AlwaysShowSelection" set to True.  So I know this is possible somehow.


howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Draw one item highlighted in TListview regardless of focus
« Reply #7 on: March 27, 2019, 12:49:13 am »
Try the attached project.
It does not mess with focus, just does custom drawing, taking account of multi-selections.

 

TinyPortal © 2005-2018