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
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
···
-----Original Message-----
From: Werner F. Bruhin [mailto:werner.bruhin@free.fr]
Sent: Saturday, July 26, 2003 6:22 AM
To: wxpython-users@lists.wxwindows.org
Subject: [wxPython-users] listCtrl (virtual) how to possition item in middle
or top of screen
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
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
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.
···
On Sat, 26 Jul 2003 15:21:58 +0200, Werner F. Bruhin <werner.bruhin@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?
--
Thanks,
Mark.