如何将光标焦点设置为特定行? [英] How do I set the cursor focus to the specific row?

查看:91
本文介绍了如何将光标焦点设置为特定行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MFC VC ++编写监控程序代码。



它显示ListCtrl屏幕上的数据,listctrl有10列报告样式。



虽然屏幕不滚动,但它会直接聚焦一行。



但屏幕确实滚动如果我将一行聚焦,光标会覆盖更多的行,并且会覆盖整个屏幕。



我想在滚动监视器屏幕的同时直接对焦一行。 ListBtrl的OnInitDialog()和NM_CLICK事件,我使用了几个样式,如下所示。

I use MFC VC++ to code a monitor program.

It shows the data on the ListCtrl screen, the listctrl has 10 columns with report style.

While the screen does not scroll, it is focused by one row directly.

But while the screen does scroll, if I focus one row, the cursor cover more rows and grows covering full screen.

I want to do focusing one row directly while scrolling of monitor screen.

OnInitDialog() and NM_CLICK event of the ListCtrl, I used several Styles like as follows.

//m_List_2100.ModifyStyle(LVS_TYPEMASK, LVS_REPORT);
//DWORD dwEXStyle = m_List_2100.GetExtendedStyle();
//m_List_2100.SetExtendedStyle(dwEXStyle | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
////m_List_2100.SetExtendedStyle(dwEXStyle | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_TRACKSELECT);
 
m_List_2100.ModifyStyle(0, LVS_REPORT, NULL);
//m_List_2100.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_GRIDLINES | LVS_EX_ONECLICKACTIVATE);
m_List_2100.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);

On the NM_CLICK events:
void CForm2000::OnNMClickList2100(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<lpnmitemactivate>(pNMHDR);
	
	NMLISTVIEW *pNMListCtrl = (NMLISTVIEW*)pNMHDR;
	int nSelectIndex = pNMListCtrl->iItem;

	m_List_2100.SetItemState(nSelectIndex, LVIS_SELECTED, LVIS_SELECTED);
	m_List_2100.EnsureVisible(nSelectIndex, TRUE);	
	m_List_2100.SetFocus();
}





谢谢。



我尝试了什么:



我编码了上述条件,但都失败了。



Thank you.

What I have tried:

I was coding as many conditions of above, but all failed.

推荐答案

OnNMClickList2100 处理程序中,单击它时选择一个项目(一行)。但是这不会从其他实际选择的行中删除选择,因此您可能有多个选定的行。



自己处理它的目的是什么?默认处理将选择单击的行,并根据Shift和Ctrl键状态选择/取消选择其他行。如果您不想进行多项选择,请设置 LVS_SINGLESEL 样式。



您告诉我们有当你浏览列表时出现问题。但是您显示的代码与滚动无关(除了您在滚动时单击一行)。所以问题可能位于代码中的其他位置。检查您是否也在其他地方更改选择(特别是在滚动相关功能中)以及是否真的有必要。
In your OnNMClickList2100 handler you are selecting an item (a row) when clicked on it. But this will not remove the selection from other actually selected rows so that you may have multiple selected rows.

What is the purpose of handling that on your own? The default handling will select the clicked row and select / deselect others depending on the Shift and Ctrl key states. If you don't want multi selections, set the LVS_SINGLESEL style.

You are telling us that there are problems when you scoll through the list. But the code shown by you is not related to scrolling (besides you are clicking on a row while scrolling). So the problem is probably located somewhere else in your code. Check if you are changing the selection elsewhere too (especially in scrolling related functions) and if that is really necessary.


这篇关于如何将光标焦点设置为特定行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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