Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Multiple TListViews in TScrollBox - maintaining selected row



Permlink Replies: 1 - Last Post: Apr 4, 2016 9:55 AM Last Post By: Remy Lebeau (Te...
Gregory Klas

Posts: 6
Registered: 8/18/01
Multiple TListViews in TScrollBox - maintaining selected row
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 3, 2016 1:54 AM
Hello,

I'm working on an application with Cascading Lists (like the Mac OSX Column Browser). I need to dynamically create any number of TListViews extending off to the right inside a TScrollBox. Each TListView has ViewStyle set to vsReport and RowSelect is set to true.

The problem is that I lose the highlighted row when the focus moves from one TListView to another inside the TScrollBox. In my application the user needs to select several values across these TListViews to ultimately define pairs or sets of rows that belong together.

I could be wrong but I think the style of the ListView needs to be set to LVS_SHOWSELALWAYS. Unfortunately it's not working yet. There's probably something simple I'm missing or my approach is not correct. Maybe it's something outside my function or at the form level. If anyone can point me in the right direction, I'd be extremely appreciative. Thanks in advance!

for(int Num = 0; Num < SomeNumber; Num++)
{
TListView *LV = new TListView(ScrollBox1);
LV->Parent = ScrollBox1;
LV->ViewStyle = vsReport;
LV->RowSelect = true;

// set proper position here, fill the ListView, etc.

// attempt to set it up so the selected row in this
// ListView will stay selected when other ListViews inside the
// ScrollBox are focused and items are being selected.

LONG_PTR p_lpLV = GetWindowLong(LV->Handle, GWL_STYLE);
SetWindowLong(LV->Handle, GWL_STYLE, (p_lpLV | LVS_SHOWSELALWAYS));
}

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Multiple TListViews in TScrollBox - maintaining selected row
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2016 9:55 AM   in response to: Gregory Klas in response to: Gregory Klas
Gregory wrote:

The problem is that I lose the highlighted row when the focus moves
from one TListView to another inside the TScrollBox. In my application
the user needs to select several values across these TListViews to
ultimately define pairs or sets of rows that belong together.

The TListView::HideSelection property is true by default. Set it to false
instead.

I could be wrong but I think the style of the ListView needs to be set
to LVS_SHOWSELALWAYS.

The HideSelection property manages that style.

Unfortunately it's not working yet.

That is because you are manipulating the ListView's HWND directly. If the
HWND ever gets re-created at runtime (which can happen), your custom setting
will be lost (unless you subclass the ListView to re-assign the value on
each HWND recreation). Use the HideSelection property instead, let the ListView
handle that detail for you:

LV->HideSelection = false;


--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02