Click here to Skip to main content
15,920,956 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
void CListView::OnInitialUpdate()
{
	CListView::OnInitialUpdate();


	// TODO: You may populate your ListView with items by directly accessing
	//  its list control through a call to GetListCtrl().

	
	// Add the parent item
	GetListCtrl().InsertColumn(0, _T("Column Text"), LVCFMT_LEFT, 200);
	
	GetListCtrl().SetImageList(&m_ImageSmall, LVSIL_SMALL);
	GetListCtrl().SetImageList(&m_ImageLarge, LVSIL_NORMAL);

	// Add children
	for( int i = 1; i < 5; i++ ) {
		GetListCtrl().InsertItem (0, _T("Child of Parent Item"));
	}

	CHeaderCtrl hc;
	if (hc.IsKindOf(RUNTIME_CLASS(CHeaderCtrl)))
	{
		int i = 0;//ok
	}

	if (GetListCtrl().GetHeaderCtrl()->IsKindOf(RUNTIME_CLASS(CHeaderCtrl)))
	{
	        //fail to step in, why?
		HWND hWndHeader = GetListCtrl().GetDlgItem(0)->GetSafeHwnd();
		m_flatHeader.SubclassWindow (hWndHeader);
	
	}
}


Why is it unable to step into the second "if"?
Posted
Updated 23-Feb-14 15:24pm
v4
Comments
[no name] 18-Feb-14 21:48pm    
Question?
shdj111 19-Feb-14 4:23am    
yes
Malli_S 19-Feb-14 2:08am    
Did you check for last error? err value or GetLastError() ?
Richard MacCutchan 19-Feb-14 5:11am    
I have a feeling (the documentation does not make this clear) that this only works with instantiated objects, not with pointers. You can easily test that with your debugger.
Stefan_Lang 19-Feb-14 5:21am    
Is that your actual code? The second if appears to be missing a closing bracket. Then again it shouldn't compile to start with...

Please check whether your list view is created using LVS_REPORT style. If not, add this style.
 
Share this answer
 
IsKindOf only works if certain conditions are met.

http://msdn.microsoft.com/en-us/library/b7tsah76.aspx[^]

The test you are doing seems redundant:

C++
GetListCtrl().GetHeaderCtrl()->IsKindOf(RUNTIME_CLASS(CHeaderCtrl))


GetListCtrl().GetHeaderCtrl() either returns a CHeaderCtrl or NULL. That's it.

http://msdn.microsoft.com/en-us/library/c4s15zsx.aspx[^]
 
Share this answer
 
v2

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