Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 455
  • Last Modified:

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

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
shawn226
Asked:
shawn226
  • 8
  • 4
  • 4
  • +2
1 Solution
 
jimyXCommented:
Set HideSelection property to False
0
 
Ephraim WangoyaCommented:


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
 
shawn226Author Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Ephraim WangoyaCommented:

The light shade is probably because it has no focus, use the two methods together
0
 
shawn226Author Commented:
Yes, I did try the two methods together. Did just the same as JimyX's alone.
0
 
Ephraim WangoyaCommented:

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
 
shawn226Author Commented:
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
 
jimyXCommented:
You can use this code at your FormOnPaint event:
procedure TForm1.FormPaint(Sender: TObject);
begin
  ListView1.SetFocus;
end;

Open in new window

0
 
shawn226Author Commented:
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
 
jimyXCommented:
Do you have the ListView on PageControl?
0
 
shawn226Author Commented:
I'm using TabbedNotebook
0
 
jimyXCommented:
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
 
RezaSadighCommented:
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
 
systanCommented:
Put your ListView1.SetFocus in TabbedNotebook_Enter
procedure TForm1.TabbedNotebook1Enter(Sender: TObject);
begin
...SetFocus
end;

Open in new window

0
 
systanCommented:
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
 
shawn226Author Commented:
That worked JimyX, thanks!

Thanks to all others who replied also!

Cheers
   Shawn
0
 
Ephraim WangoyaCommented:

How interesting, I gave the same answer but mine did not work somehow, LOL
0
 
shawn226Author Commented:
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
 
systanCommented:
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
 
shawn226Author Commented:
Systan - as I mentioned in my original question post, I am already selecting an item.

Regards
   Shawn
0
 
systanCommented:
Ok;
I got it, your looking for the pageindex, the current page to setfocus.


Good Luck
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 4
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now