Jump to content
  • Advertisement
Sign in to follow this  
fathom88

Silly Question On MFC CListCtrl

This topic is 4473 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a question regarding CListCtrl. I can't seem to add header columns to it. I can make entries just fine, but not headers. I dragged and dropped the control to my window from the tool box. I set the view mode to report in the properties window. I placed it's intialization in my window's OnInitDialog. Here it is: BOOL CMyTestWin::OnInitDialog() { CListCtrl *pListCtrl = NULL; LVCOLUMN lvColumn; LVITEM lvItem; CDialog::OnInitDialog(); pListCtrl = (CListCtrl *)GetDlgItem(IDC_TEST_LIST_CTRL); if(pListCtrl != NULL) { pListCtrl->SetExtendedstyle(LVS_EX_CHECKBOXES); lvColumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH; lvColumn.fmt = LVCFMT_LEFT; lvColumn.cx = 120; lvColumn.pszText = "Full Name"; pListCtrl->InsertColumn(0, &lvColumn); lvColumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH; lvColumn.fmt = LVCFMT_LEFT; lvColumn.cx = 100; lvColumn.pszText = "Profession"; pListCtrl->InsertColumn(1, &lvColumn); lvColumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH; lvColumn.fmt = LVCFMT_LEFT; lvColumn.cx = 80; lvColumn.pszText = "Fav Sport"; pListCtrl->InsertColumn(2, &lvColumn); lvColumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH; lvColumn.fmt = LVCFMT_LEFT; lvColumn.cx = 75; lvColumn.pszText = "Hobby"; pListCtrl->InsertColumn(3, &lvColumn); //adding item OK lvItem.mask = LVIF_TEXT; lvItem.iItem = 0; lvItem.iSubItem = 0; lvItem.pszText = "Just A TEST"; pListCtrl->InsertItem(&lvItem); } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } I get no columns. It should work. I got the example from FunctionX. Am I forgetting to set a property in the control settings? Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
It's not that silly a question. I had a quick look in the MSDN and it looks like you can only have a header when you use the "report" style. There's a column heading parameter in the InsertColumn method of the control (EDIT: Just noticed there are two versions of that function, and the one you're using with a LVCOLUMN should work fine too, you just have to get it into report mode)

Hope that helps get you started

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!