Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i tried to insert an item to the clistctrl,it just isn't working.


the code is shown below.
BOOL SoftwareResource::OnInitDialog() {
	CDialogEx::OnInitDialog();
	LONG style;
	style = GetWindowLong(m_list.m_hWnd, GWL_STYLE);
	SetWindowLong(m_list.m_hWnd, GWL_STYLE, style | LVS_REPORT);

	m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT |LVS_EX_CHECKBOXES | LVS_EX_DOUBLEBUFFER|LVS_OWNERDATA);
	LPCTSTR tab[4] = { _T("PName"),_T("pid"),_T("Thread Num"),_T("Parent id") };
	for (int i = 0; i < 4; i++)
	{
		m_list.InsertColumn(i, tab[i]);
		m_list.SetColumnWidth(i, 200);
	}
	
	m_list.SetRedraw(FALSE);
	LPCTSTR str;
	str = _T("madison");
	
	
	int nRow=m_list.InsertItem(0, str);
	m_list.SetItemText(nRow, 0, str);
	for (int i = 1; i < 10; i++)
		m_list.InsertItem(i, str);
	
	m_list.SetRedraw(TRUE);
	
	return TRUE;
}


What I have tried:

i already set the attribute view as report,yet it still doens't show the text.i could see that there are visible views in the list,but without text.i tried updatedata,setredraw,but it still doesn't work.and when i tried to use setitemtext to set the text,it reported a debug assertion fail.

ps.the insertcolumn is working,though.i don't know why this could work but the insertitem couldn't work.
Posted
Updated 27-Apr-21 21:59pm

1 solution

You are using the LVS_OWNERDATA style in your control which means that the rows do not hold any data, it is provided dynamically via callbacks. Se About List-View Controls - Win32 apps | Microsoft Docs[^].
 
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