Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
C#
//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.
Posted
Updated 22-Jun-16 21:08pm
v2

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900