listCtrl (virtual) how to possition item in middle or top of screen

1 view
Skip to first unread message

Werner F. Bruhin

unread,
Jul 26, 2003, 9:21:58 AM7/26/03
to wxpytho...@lists.wxwindows.org
I am using a virtual listctrl to allow user to search for some data,
when found I like to show it in the listctrl.

I got it basically to work, but the "found item" shows as the last or
second to last item in the list (most of the time), is there an easy way
to possition it at the top of the listctrl?

I tried both
list.Focus(item)
list.EnsureVisible(item)

wxPython 2.4.0.7 on Win XP

Thanks for any hints
Werner


John Hopkins

unread,
Jul 26, 2003, 12:26:38 PM7/26/03
to wxPytho...@lists.wxwindows.org
You have to scroll the list, which takes *pixels* rather than *rows* as the
argument. I did it like this:

Index = self.itemkey[self.ClientID]
self.ClientList.SetItemState(Index, wxLIST_STATE_SELECTED,
wxLIST_STATE_SELECTED)
height = self.ClientList.GetItemRect(Index, code = wxLIST_RECT_BOUNDS)[1]
self.ClientList.ScrollList(0, height-50)

The "-50" is kind of a "fudge factor". You may need a different number.

John Hopkins
Hopkins IT


---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-user...@lists.wxwindows.org
For additional commands, e-mail: wxPython-...@lists.wxwindows.org

Mark Melvin

unread,
Jul 27, 2003, 11:49:00 AM7/27/03
to wxpytho...@lists.wxwindows.org
On Sat, 26 Jul 2003 15:21:58 +0200, Werner F. Bruhin
<werner...@free.fr> wrote:

> I am using a virtual listctrl to allow user to search for some data, when
> found I like to show it in the listctrl.
>
> I got it basically to work, but the "found item" shows as the last or
> second to last item in the list (most of the time), is there an easy way
> to possition it at the top of the listctrl?
>

Hi Werner,

I am doing the exact same thing but positioning the item in the middle of
the control. Here is my method:

# ----
def ScrollToItem(self, index):
top_value = max([0, index - self.GetCountPerPage() / 2])
bottom_value = min([index + self.GetCountPerPage() / 2,
self.GetItemCount() - 1])
self.EnsureVisible(top_value)
self.EnsureVisible(bottom_value)
# ----
def SelectAndScrollToItem(self, index):
self.ScrollToItem(index)
self.SetItemState(index,
wxLIST_STATE_FOCUSED|wxLIST_STATE_SELECTED,

wxLIST_STATE_FOCUSED|wxLIST_STATE_SELECTED)


You could use the same sort of logic to scroll the item to the top.
Basically what you would do is call:

self.EnsureVisible(your_index + self.GetCountPerPage)
self.EnsureVisible(your_index)

But checkng for bounds as appropriate. I think this is what you are after.


--
Thanks,
Mark.

Reply all
Reply to author
Forward
0 new messages