Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 572
  • Last Modified:

CListCtrl

...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...
0
Yurich
Asked:
Yurich
1 Solution
 
northernchillCommented:
I can't answer your first question, but this link should answer the second.

http://www.codeguru.com/listview/change_row_height.shtml
0
 
jackrabbit22Commented:
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);
}
0
 
YurichAuthor Commented:
...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...
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

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

Tackle projects and never again get stuck behind a technical roadblock.
Join Now