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
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
> 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.