CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Posts
    2

    Cannot setupt image for the header of listctrl

    Hi all,

    I am using Iuri's GfxListCtrl in a formview, but cannot display images in its column headers. What I have found is that SetItem of CListCtrl is sucessful only for the first column then fails for all other columns. I have tried following code:
    for(idx = 0; idx < 5; idx++ )
    {
    iChkIdx = pList->InsertColumn(idx, "");
    pList->wndHeader.GetItem(iChkIdx, &hditem );
    pList->wndHeader.SetItem(iChkIdx, &hditem );
    }

    SetItem returns 1 only when idx = 0 but GetItem returns 1 for all idx. Actually these functions are from CListCtrl (not GfxListCtrl). Because it fails to setup data, the header images are not drawn.

    Has anyone any idea? Thank in advance!

    Da


  2. #2
    Join Date
    Apr 1999
    Location
    Bangalore, India
    Posts
    25

    Re: Cannot setupt image for the header of listctrl

    If I am not wrong, you want to display images in the column headers. I did it for a CListCtrl in a dialog box. Create and set an image list for the listctrl.



    m_ImageList.Create(IDB_MYICON,16,1,RGB(255, 255, 255));
    m_listctrl.SetImageList(&m_ImageList,LVSIL_SMALL);





    Add columns, items and subitems whichever way you want to. Then add the following code



    LV_COLUMN lvc;
    CImageList* pImageList;
    for(int i=0; i<3; i++)//Max no of col = 3
    {

    // Set column mask
    lvc.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_WIDTH;

    // Get column info
    m_listctrl.GetColumn(i, &lvc);

    // Set image for the column mask
    lvc.mask |= LVCF_IMAGE ;
    lvc.fmt |= LVCFMT_IMAGE | LVCFMT_LEFT;
    pImageList = m_listctrl.GetImageList(LVSIL_SMALL);

    // Set image index
    lvc.iImage = i;

    // Finally set the column with image
    m_listctrl.SetColumn(i, &lvc);





    I did this in OnInitDialog(). You can decide where you want to add images to the headers.

    Hope this helps you.

    Cheers!!!!

    Vikrant Bapat
    [email protected]


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured