listctrl中的iItem值返回-1 [英] iItem value in listctrl return -1

查看:379
本文介绍了listctrl中的iItem值返回-1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望获得列表控件的行和列,当我点击时,我点击,

我使用以下代码,

isubitem值是okey,但是iItem值当我点击第一列时为0,当我点击其他列时为-1,

如何获得其他colomns值以及我的代码中出现了什么问题?

等待你。



我的尝试:



I want to get row and column of list control where I click when I clicked,
I use the following code,
isubitem value is okey , but iItem value is 0 when I click on first column and -1 when I click other columns ,
how Can I get other colomns value and what is wrong in my code?
Waiting for you.

What I have tried:

void MyView::OnNMClickList3(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	int r = pNMItemActivate->iSubItem;
	int t = pNMItemActivate->iItem;
	*pResult = 0;
}

推荐答案

查看 NM \_CLICK(列表视图)通知代码| Microsoft Docs [ ^ ]:

See the description of the NM\_CLICK (list view) notification code | Microsoft Docs[^]:
Quote:

lParam的iItem成员仅在图标有效时才有效或单击第一列标签。要确定在一行中的其他位置发生单击时选择了哪个项目,请发送LVM_SUBITEMHITTEST消息。

The iItem member of lParam is only valid if the icon or first-column label has been clicked. To determine which item is selected when a click takes place elsewhere in a row, send an LVM_SUBITEMHITTEST message.



将此添加到您的代码中(未经测试):


Add this to your code (untested):

if (t < 0)
{
    LVHITTESTINFO tHitTest;
    tHitTest.pt = pNMItemActivate->ptAction;
    // This assumes that MyView is the list view for which the message is processed.
    // If not, you have to send the message to the list using it's member variable
    //  or ::SendMessage passing it's HWND
    t = SendMessage(LVM_SUBITEMHITTEST, 0, reinterpret_cast<LPARAM>(&tHitTest));
}


这篇关于listctrl中的iItem值返回-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆