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.