Article ID: 151897
Article Last Modified on 11/21/2006
// m_pList is of type CListCtrl*
BEGIN_MESSAGE_MAP(CTestView, CView)
ON_NOTIFY (LVN_GETDISPINFO, IDC_LIST, OnGetDispInfo)
END_MESSAGE_MAP()
int CTestView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
// create CListCtrl and columns
...
// insert item; text will be set in LVN_GETDISPINFO
m_pList->InsertItem (iIndex, LPSTR_TEXTCALLBACK);
...
}
void CTestView::OnGetDispInfo (NMHDR* pnmhdr, LRESULT* pResult)
{
LV_DISPINFO* pdi = (LV_DISPINFO *) pnmhdr;
// set text for column #1
if (0 == pdi->item.iSubItem)
pdi->item.pszText = "1st Column Data";
// set text for column #2
else if (1 == pdi->item.iSubItem)
pdi->item.pszText = "2nd Column Data";
// set text for column #3
else if (2 == pdi->item.iSubItem)
pdi->item.pszText = "3rd Column Data";
}
int CTestView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
// create CListCtrl and columns
...
// create 3rd column with zero width so it is not visible
m_pList->InsertColumn (2, "", LVCFMT_LEFT, 0);
// add items
...
return 0;
}
// this function makes the 3rd column appear
void CTestView::AddColumn()
{
LV_COLUMN lvc;
lvc.mask = LVCF_TEXT | LVCF_WIDTH;
lvc.cx = 100;
lvc.pszText = "Column #3";
// set the text and width of column #3
m_pList->SetColumn (2, &lvc);
}
/* Compile options needed: default
*/
Additional query words: kbVC400bug
Keywords: kbbug kbfix kblistview kbuidesign kbvc500fix KB151897