[[wxPython] wxListCtrl]

I use:
  pos = self.GetIndexFromPoint( event.GetPosition() )
where:
    def GetIndexFromPoint( self, point ):
        return self.HitTest( point )[0]
and it works!

Niki Spahiev
e-mail: niki@vintech.bg

···

JB <jimbag@kw.igs.net> wrote:

*sigh*... here's what I've written (which of course does not work)...

def OnRightDown( self, event ):
  (iid, flag) = self.listctrl.HitTest((event.GetX(),event.GetY()))
  if flag & wxLIST_HITTEST_ONITEM:
    self.listctrl..SetItemState( iid, wxLIST_STATE_SELECTED, ...etc...

iid is always -1 no matter where I hit the list.

____________________________________________________________________
Get free email and a permanent address at Net@ddress Mail

_______________________________________________
wxPython-users maillist - wxPython-users@starship.python.net
http://starship.python.net/mailman/listinfo/wxpython-users

Hi.

I'm currently having the same problem as JB, but Niki's suggestion
won't work. I always get the tuple (-1, 18) for HitTest on a
wxListCtrl. Am I not using it correctly?
Does someone have a solution? (wxPython-2.1.15 on Linux)

Here's test code:

···

---------------------------------------------------------------------------
from wxPython.wx import *

class MyFrame(wxFrame):
    def __init__(self, parent):
        wxFrame.__init__(self, parent, -1, "test", size=(400, 200))
        self.lc = wxListCtrl(self, -1, style = wxLC_LIST)
        for i in range(10):
            self.lc.InsertStringItem(i, "%d" % i)
        
        EVT_LEFT_DOWN(self.lc, self.OnLeftClick)

    def OnLeftClick(self, event):
        print self.lc.HitTest(event.GetPosition()) # This prints (-1, 18)
  event.Skip()

class MyApp(wxApp):
    def OnInit(self):
        frame = MyFrame(NULL)
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

app = MyApp(0)
app.MainLoop()
---------------------------------------------------------------------------

From: JB <jimbag@kw.igs.net>
Subject: [wxPython] wxListCtrl
Date: Fri, 24 Mar 2000 01:53:31 -0500

*sigh*... here's what I've written (which of course does not work)...

def OnRightDown( self, event ):
  (iid, flag) = self.listctrl.HitTest((event.GetX(),event.GetY()))
  if flag & wxLIST_HITTEST_ONITEM:
    self.listctrl..SetItemState( iid, wxLIST_STATE_SELECTED, ...etc...

iid is always -1 no matter where I hit the list.

From: Niki Spahiev <niki.spahiev@usa.net>
Subject: Re: [[wxPython] wxListCtrl]
Date: 24 Mar 00 14:01:42 EET

I use:
  pos = self.GetIndexFromPoint( event.GetPosition() )
where:
    def GetIndexFromPoint( self, point ):
        return self.HitTest( point )[0]
and it works!

--
Hideo Bannai