[英]wxListCtrl GetColumn() error?
I have a listctrl in my program, which has two columns that are populated with lots of elements. 我的程序中有一个listctrl,其中有两列,其中填充了许多元素。 When the user clicks on one of them with a right click, I would like to know in which of the two columns the element lives.
当用户单击鼠标右键时,我想知道该元素位于哪两列中。
My problem - the GetColumn() function returns either -1 (aka not found) or a zero -> even due I clicked in the second column (which should be 1 - they start from 0). 我的问题-GetColumn()函数返回-1(即未找到)或零->即使我单击第二列(应该为1-它们从0开始)也是如此。
I had a look at the sample/listctrl but even there, GetColumn() always returns a 1 even if i click in another column. 我看了一下sample / listctrl,但是即使在那儿,即使我单击另一列,GetColumn()也会始终返回1。
I use wxWidgets 2.9.5 on Windows 7. 我在Windows 7上使用wxWidgets 2.9.5。
Here the code that i thought should work but doesn't: 我认为在这里的代码应该起作用,但是不起作用:
Connect(ID_LISTBOX,wxEVT_LIST_ITEM_RIGHT_CLICK,wxListEventHandler(X::OnRightClick));
....
void X::OnRightClick(wxListEvent& event)
{
int a = event.GetColumn(); // returns - 1 aka not found
int b = wxListItem(event.GetItem()).GetColumn(); // returns zero regardless of the column
event.Skip();
}
How do I find out which column my element is in? 如何找出我的元素在哪一列?
Thanks 谢谢
GetColumn()
only works for EVT_LIST_COL_XXX
events, ie clicking on the column itself, as explicitly mentioned in the documentation. 如文档中明确提到的,
GetColumn()
仅适用于EVT_LIST_COL_XXX
事件,即单击列本身。 For the item clicks you need to explicitly call HitTest() and examine its return value and ptrSubItem
output parameter value. 对于项目单击,您需要显式调用HitTest()并检查其返回值和
ptrSubItem
输出参数值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.