Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to leave a TListView item 'selected' after leaving one screen then returning

Posted on 2011-03-18
21
447 Views
Last Modified: 2012-05-11
Hi, in my TListView box I have several items.. I have it set up so when I double-click on an item, it takes me to another tab screen of my program and displays further detail about my selection. No problem there, but when I return back to my original screen that has the TListView, the item I double-clicked before no longer shows as 'selected'/hi-lited. Is these some where to leave that item hi-lited?

Thanks
  Shawn
0
Comment
Question by:shawn226
  • 8
  • 4
  • 4
  • +2
21 Comments
 
LVL 24

Expert Comment

by:jimyX
ID: 35168766
Set HideSelection property to False
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 35168792


Just call ListView.SetFocus when you come back to the tab with the list view
procedure TForm1.PageControl1Change(Sender: TObject);
begin
  if PageControl1.ActivePage = ListViewPage then
    ListView1.SetFocus;
end;

Open in new window

0
 

Author Comment

by:shawn226
ID: 35169195
Thanks guys. Jimyx - your suggestion does work, but it only highlights the ListView item in a very light shade of gray. I was hoping it would highlight it in the blue color as when I first selected it.

Ewangoya - your suggestion didn't seem to do anything at all, I'm afraid  :-(

Thanks
   Shawn
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 32

Expert Comment

by:ewangoya
ID: 35169233

The light shade is probably because it has no focus, use the two methods together
0
 

Author Comment

by:shawn226
ID: 35169253
Yes, I did try the two methods together. Did just the same as JimyX's alone.
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 35169305

I suppose you have to save the selected index and reset it again once you go back to the tab with the ListView
I have not tested this though
procedure TForm3.PageControl1Changing(Sender: TObject;
  var AllowChange: Boolean);
begin
    FFocusedItem := ListView1.ItemFocused;
end;

procedure TForm1.PageControl1Change(Sender: TObject);
begin
  if PageControl1.ActivePage = ListViewPage then
  begin
    ListView1.ItemFocused := FFocusedItem ;
    ListView1.SetFocus;
  end;
end;

Open in new window

0
 

Author Comment

by:shawn226
ID: 35169402
Nope, still shows it only is a light shade of gray. I have to then manually give focus to the ListView (by clicking on a column to sort) in order for the item to be highlighted in blue.

Thanks
   Shawn
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35169974
You can use this code at your FormOnPaint event:
procedure TForm1.FormPaint(Sender: TObject);
begin
  ListView1.SetFocus;
end;

Open in new window

0
 

Author Comment

by:shawn226
ID: 35170056
Thanks JimyX, but I have several tabs/screens in my program and I don't always want to have the focus on the tab with the ListView box.
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35170068
Do you have the ListView on PageControl?
0
 

Author Comment

by:shawn226
ID: 35170079
I'm using TabbedNotebook
0
 
LVL 24

Accepted Solution

by:
jimyX earned 50 total points
ID: 35170101
Then at the TabbedNotebookOnClick event put this code:
procedure TForm1.TabbedNotebook1Click(Sender: TObject);
begin
  if TabbedNotebook1.PageIndex = 0 then  // provide the index where you have the ListView (zero is the first tab - or you can look by the tab's name)
    ListView1.SetFocus;
end;

Open in new window

0
 
LVL 2

Expert Comment

by:RezaSadigh
ID: 35170122
Hi my friend,

In your main question you said: "when I return back to my original screen that has the TListView," put the
ListView1.SetFocus; where that run when you back to your original screen.

Best regards.
0
 
LVL 14

Expert Comment

by:systan
ID: 35170265
Put your ListView1.SetFocus in TabbedNotebook_Enter
procedure TForm1.TabbedNotebook1Enter(Sender: TObject);
begin
...SetFocus
end;

Open in new window

0
 
LVL 14

Expert Comment

by:systan
ID: 35170330
I test this one, it works;

procedure TForm1.TabbedNotebook1Click(Sender: TObject);
begin
//SAMPLE your listView1 is in PageIndex 0
if TabbedNotebook1.PageIndex = 0 then
ListView1.SetFocus;
ListView1.Items.Item[0].Selected := True;
end;

But you can also put this lines in TabbedNotebook_Enter<probably>
0
 

Author Closing Comment

by:shawn226
ID: 35173190
That worked JimyX, thanks!

Thanks to all others who replied also!

Cheers
   Shawn
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 35173213

How interesting, I gave the same answer but mine did not work somehow, LOL
0
 

Author Comment

by:shawn226
ID: 35173233
Ewangoya, your answer suggested using the TabbedNotebookChange event... which did not seem to work. JimyX's answer was using the TabbedNotebookClick event. Sorry!

Regards
   Shawn
0
 
LVL 14

Expert Comment

by:systan
ID: 35173956
You can't see the focus without selecting the item;
ListView1.Items.Item[0].Selected := True;

Open in new window

I don't agree with this; anyway it's 50 only.
0
 

Author Comment

by:shawn226
ID: 35176459
Systan - as I mentioned in my original question post, I am already selecting an item.

Regards
   Shawn
0
 
LVL 14

Expert Comment

by:systan
ID: 35185604
Ok;
I got it, your looking for the pageindex, the current page to setfocus.


Good Luck
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
add combobox item based on numbers 9 154
Making delphi communicate with a c# service 16 111
Performance of SQL statement 37 127
Slow Restore if incremental backups using RDiff.exe 4 29
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question