Sign in to follow this  
fathom88

Silly Question On MFC CListCtrl

Recommended Posts

fathom88    180
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
AndyGeers    132
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this