[英]Retrieving the selected row in a CListCtrl
I have a CListCtrl
in which there are 2 columns and multiple rows. 我有一个
CListCtrl
,其中有2列和多行。 I want to get the the index of the selected row. 我想获取所选行的索引。 I am able to get the row when the user clicks on the first column but could not when clicked on the second column.
当用户单击第一列时,我能够获得该行,但是当单击第二列时,则无法。
Any suggestions ? 有什么建议么 ?
Call m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT);
调用
m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT);
after the creation of the control - usually in OnInitDialog
. 创建控件后-通常在
OnInitDialog
。
Let's say, that we have a Dialog with one CListCtrl object defined in the RC file like this: 假设,我们有一个带有RC文件中定义的CListCtrl对象的对话框,如下所示:
IDD_DIALOG DIALOGEX 0, 0, 435, 273 STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "A Dialog :)" FONT 12, "Microsoft Sans Serif", 400, 0, 0xEE BEGIN CONTROL "",IDC_LIST_CONTROL,"SysListView32",LVS_REPORT | LVS_OWNERDRAWFIXED | LVS_ALIGNLEFT | WS_BORDER,5,138,350,86 END
Then the CListCtrl object IDC_LIST_CONTROL behaves as a LVS_REPORT, which means that clicking on any of its column selects the whole row. 然后,CListCtrl对象IDC_LIST_CONTROL表现为LVS_REPORT,这意味着单击其任何列都会选择整个行。
Then the selected row is retrieved like this: 然后按以下方式检索所选行:
int selectedRow = ((CListCtrl*)GetDlgItem(IDC_LIST_CONTROL))->GetSelectionMark(); int selectedRow =(((CListCtrl *)GetDlgItem(IDC_LIST_CONTROL))-> GetSelectionMark();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.