Problem with inserting images as items in CListCtrl - Programmer

This is a discussion on Problem with inserting images as items in CListCtrl - Programmer ; I want to insert images in ListCtrl throgh resource editor. In OnCREATE of CDialog Derived class ...... Here is the code .Tell me where I am going wrong CImageList *m_pImageList; m_pImageList = new CImageList(); m_myListCtrl.InsertColumn(0,TEXT("aaaa")); m_myListCtrl.InsertColumn(1,TEXT("bbbb")); m_myCtrl.InsertColumn(2,TEXT("cccc")); m_myListCtrl.SetColumnWidth(0, 100); m_myListCtrl.SetColumnWidth(1, ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: Problem with inserting images as items in CListCtrl

  1. Problem with inserting images as items in CListCtrl

    I want to insert images in ListCtrl throgh resource editor.
    In OnCREATE of CDialog Derived class ......
    Here is the code .Tell me where I am going wrong

    CImageList *m_pImageList;
    m_pImageList = new CImageList();

    m_myListCtrl.InsertColumn(0,TEXT("aaaa"));
    m_myListCtrl.InsertColumn(1,TEXT("bbbb"));
    m_myCtrl.InsertColumn(2,TEXT("cccc"));

    m_myListCtrl.SetColumnWidth(0, 100);
    m_myListCtrl.SetColumnWidth(1, 100);
    m_myListCtrl.SetColumnWidth(2, 100);

    ASSERT(m_pImageList != NULL); // serious allocation failure checking
    m_pImageList->Create(32, 32, TRUE, 4, 4);

    m_pImageList->Add(AfxGetApp()->LoadIcon(IDI_ICON1));
    m_pImageList->Add(AfxGetApp()->LoadIcon(IDI_ICON2));
    m_myListCtrl.SetImageList(m_pImageList, LVSIL_SMALL);

    I get assertion problem at creation of m_pmyLISTctRL;
    I am not able to figure it out

    afxcmn.inl line no194
    { ASSERT(::IsWindow(m_hWnd)); return (int) ::SendMessage(m_hWnd,
    LVM_INSERTCOLUMN, nCol, (LPARAM)pColumn); }


  2. Re: Problem with inserting images as items in CListCtrl

    I added this code in oninitdialog then it started working ,but images
    are missing ,
    can some one help me here.
    thanks


  3. Re: Problem with inserting images as items in CListCtrl

    OnCreate is not going to be called for a dialog. Use OnInitDialog
    instead. You can create/initialize the imagelist in Dialog's
    constructor if you want.

    ---
    Ajay


  4. Re: Problem with inserting images as items in CListCtrl

    I added the code inOnInitDilaog so no assertion but images are
    invisible.
    :-(


  5. Re: Problem with inserting images as items in CListCtrl

    I created the list control with view set to small icon .
    Is that I am missing basics ?


  6. Re: Problem with inserting images as items in CListCtrl

    Yes - you need to:

    1. create & populate a CIMageList object
    2. call CListCtrl::setImageList(...) with the initialized object
    3. use image index when calling CListCtrl::InsertItem

    wrote in message
    news:1148497152.520689.59110@g10g2000cwb.googlegro ups.com...
    >I created the list control with view set to small icon .
    > Is that I am missing basics ?
    >




+ Reply to Thread