MFC CListCtrl does not respond to lvn_getdispinfo messages

Source: Internet
Author: User

Today, the Write program adds a list control to the dialog box CListCtrl "dragged in controls" to display the contents of a vector in a class. Since this control has been used many times before, it has been known that if the list wants to respond to lvc_getdispinfo messages, it must be lvs_ownerdata style. So the following code is written in OnInitDialog ():

	M_listctrl.modifystyle (0, lvs_ownerdata| Lvs_report| Lvs_singlesel);
	M_listctrl.setextendedstyle (M_listctrl.getextendedstyle () | Lvs_ex_fullrowselect);
	M_listctrl.insertcolumn (0, _t ("ID"), 0,);
	M_listctrl.insertcolumn (1, _t ("Data"), 0, 300);

Then bind the message response function:

void Clistctrltestdlg::onlvngetdispinfolist1 (NMHDR *pnmhdr, LRESULT *presult)
{
	Nmlvdispinfo *pdispinfo = Reinterpret_cast<nmlvdispinfo*> (PNMHDR);
	TODO: Add control in this notification handler code
	int nitem = pdispinfo->item.iitem;
	int nsubitem = pdispinfo->item.isubitem;
	if (nsubitem==0)
		pdispinfo->item.psztext = _t ("111");
	*presult = 0;
}

I thought the program was going to work perfectly, but it didn't. Debug found, OnLvnGetDispinfoList1 (), will not enter, this pit big.

Helpless, after ModifyStyle added a getstyle () to see if there is a set in.

It turns out that it didn't.

Then, because the control is dragged in, try again and set "Owner data" to true in the control's properties.

Even if you can.

Well, take a deep breath, the programmer is not afraid of the pit. To summarize:

It is no use to set Lvs_ownerdata visual after CListCtrl create, it is necessary to write this style when create.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.