Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ListView: Scroll to selected item

868 views
Skip to first unread message

Mario Zimmermann

unread,
Jun 17, 1999, 3:00:00 AM6/17/99
to
Hello Builders!

I have a form with a TListView which it's ViewStyle property
set to vsReport.

The ListView is filled with items before the form is shown.
Based upon certain criteria, exactly one item is highlighted
within the filling process.

When the form comes up, the ListView contains the items and
one of them is highlighted, as expected.

My problem is: The ListView contains ~50 entries and the highligted
item should be in the visible area when the form comes up. This
needs the ListView entries to be scrolled, preferable so that
the highlighted item is vertically centered.

Does anyone know how this can be done?

Thanks in advance.

Mario

------------------------------------------------------------
Mario Zimmermann email: zis...@cityweb.de
Zimmermann Software
Lanfermannteich 32 phone: ++49 (0) 2307 984237
D-59192 Bergkamen (Germany) fax: ++49 (0) 2307 984238
------------------------------------------------------------

Mark Cashman (TeamB) (BCB)

unread,
Jun 17, 1999, 3:00:00 AM6/17/99
to
Hi, Mario!

You could calculate the sequence of the selected entry in the list box
vs the number in the list box to get a percentage and then scroll
accordingly (you probably need to use WinAPI to get at the scrollbars
and change their position).

Alternatively, you could keep a TMemo with a list of the currently
selected items right next to the list box.

Hope this helps.

--
------
Mark Cashman (TeamB - C++ Builder), creator of The Temporal Doorway at
http://www.temporaldoorway.com
- Original digital art, writing, music and more -
C++ Builder / JBuilder Tips and The C++ Builder Programmer's Webring
(Join us!)
http://www.temporaldoorway.com/programming/index.htm
------

Yoto Yotov

unread,
Jun 17, 1999, 3:00:00 AM6/17/99
to
> My problem is: The ListView contains ~50 entries and the highligted
> item should be in the visible area when the form comes up. This
> needs the ListView entries to be scrolled, preferable so that
> the highlighted item is vertically centered.

The ListView's Scroll method allows you to scroll by x pixels the list.

1. Start a new project.
2. Add a ListView with some sample items which exceed the viewing area.
Set its ViewStyle to vsReport.
3. Add a Button. Edit the OnClick event:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
// Get last item or any item you want
TListItem *i = ListView1->Items->Item[ListView1->
Items->Count-1];

// Calculate scroll amount
int s = i->Top - ListView1->TopItem->Top;
ListView1->Scroll(NULL, s);

// Select last item
i->Selected = true;

ListView1->SetFocus();
}

--
Yoto Yotov

Damon Chandler

unread,
Jun 17, 1999, 3:00:00 AM6/17/99
to
Hi Mario,

> My problem is: The ListView contains ~50 entries and the highligted
> item should be in the visible area when the form comes up. This
> needs the ListView entries to be scrolled, preferable so that
> the highlighted item is vertically centered.

Have a look at the MakeVisible() method of TListItem...

ListView1->Selected->MakeVisible(false);


HTH.

/*----------------------------------------*/
Damon Chandler

![ http://bcbcaq.freeservers.com ]!
CAQ2 - Answers to <Commonly Asked Questions>

0 new messages