简体   繁体   English

Lua wxwidgets wxListCtrl

[英]Lua wxwidgets wxListCtrl

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 )

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). GetIndex()event一种方法,因此您应该使用event:GetIndex() ,但是我不认为它是针对鼠标事件(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. 对于鼠标事件,您可能需要使用wxListCtrl:FindItem (如果可以通过wxlua使用)来获取最接近单击位置的项目。 To get the coordinates of the click you can use event:GetPoint() (if available) or something like this: 要获取点击的坐标,您可以使用event:GetPoint() (如果可用)或类似的方法:

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). 除了使用鼠标事件,您还可以使用wxEVT_COMMAND_LIST_ITEM_ACTIVATED ,在这种情况下,您可以执行local index = event:GetIndex() (我认为该索引基于0)。

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. 如果您使用的是wxlua,我发现它随附的示例( samples/文件夹)是wxlua API支持的解决方案的良好来源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM