1

How do I obtain the index of a line when it is clicked?

lpanelList:Connect(ID_REL_LIST, wx.wxEVT_COMMAND_LEFT_CLICK,
function (event)
local number
number = GetIndex()                           --generates an error
frame:SetStatusText("REL LIST")
wx.wxMessageBox('Clicked on rel list.',
" Rel List Clicked ",
wx.wxOK + wx.wxICON_INFORMATION,
lpanelList)
end )

1 Answers1

1

GetIndex() is a method of event, so you should be using event:GetIndex(), but I don't think it's populated for mouse events (LEFT_CLICK). For mouse events you may need to use wxListCtrl:FindItem (if it's available through wxlua) to get the item closest to the position of the click. To get the coordinates of the click you can use event:GetPoint() (if available) or something like this:

local mousePos = wx.wxGetMousePosition() -- mouse pos on screen
local clientPos = lpanelList:ScreenToClient(mousePos)

Instead of using mouse events, you can also use wxEVT_COMMAND_LIST_ITEM_ACTIVATED, in which case you can do local index = event:GetIndex() (I think this index is 0-based).

If you are using wxlua, I found the samples that are included with it (samples/ folder) a good source of solutions supported with wxlua API.

Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56