Posted on 2003-02-21
Medium Priority
Last Modified: 2013-11-20
...a couple little questions regarding manipulating CListCtrl objects...

the first one: alignment of column headers and its contents is controled through LVCFMT_LEFT, _RIGHT, and _CENTER... i have four columns and three are fine but the first one is aligned to the left regardless of my settings and there is no way to change it... what could it be?

the second one: is there a way to set a "row height" for a list? i mean to change the vertical distance between items of the list because they're quite tightly placed by default and it's not very easy to see them...
Question by:Yurich
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 7994950
I can't answer your first question, but this link should answer the second.


Accepted Solution

jackrabbit22 earned 180 total points
ID: 7996558
1)  I've found the alignment will work if you update the alignment for the column AFTER you've inserted column:

The following will center align the first column:

     LPCTSTR lpszColTitles[3] = {_T("First Name"), _T("Last Name"), _T("City")};

     for (int nCol = 0; nCol < 3; nCol++)
                // Insert new column
          m_listCtrl.InsertColumn(nCol, lpszColTitles[nCol], LVCFMT_LEFT, 120);

                // Now update it's alignment
          LVCOLUMN lvc;
          ::ZeroMemory(&lvc, sizeof(LVCOLUMN));
          lvc.mask = LVCF_FMT;
          lvc.fmt = LVCFMT_CENTER;
          m_listCtrl.SetColumn(nCol, &lvc);
     m_listCtrl.InsertItem(0, _T("Joe"));
     m_listCtrl.InsertItem(0, _T("Harry"));
     m_listCtrl.InsertItem(0, _T("Reggie"));

2)  For changing item height, I override the OnMeasureItem function in the CListCtrl's parent class:

void CMyDialog::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
     // Set the item height our list control
    if (nIDCtl == IDC_MY_LISTCTRL)
        lpMeasureItemStruct->itemHeight = 18;
     CDialog::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
LVL 21

Author Comment

ID: 8019370
...neither of suggestions would work for row height because my list resides in the dialog box and in this case WM_MEASUREITEM is not processed at all... all sizes are predefined during creation of the list in dialog box editor... yet, the first part works just fine, thanks...

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month12 days, 20 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question