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

    display icons in a column of a list view control

    Dear friends:

    My application need to display an icon on the first column in a list view control. I have two icons: IDI_ICON1, IDI_ICON2. There is a flag (m_flag) to
    control when to display which icon. when m_flag is 0, IDI_ICON1 is displayed. Otherwise, IDI_ICON2 is displayed. I tried the following code, but it didn't work. I mean I didn't see the icon displayed in the first column of the list
    view control

    (1). Create a CBitmap. I tried to create a bitmap by resource editor. Then
    I had the bitmap ID: IDB_BITMAP1. Question here is: How to set up the Height
    and width of the bitmap ? Can I have a way to directly copy two icons in a
    bitmap the I created by resource editor ?

    (2). I declare a variable of CImageList. Then I tried to create a image list of the bitmap.And I added icons to the image list.
    CImageList m_IconImageList;
    m_IconImageList.Create(IDB_BITMAP1, 32, 1, 24, NULL);
    m_IconImageList.Add((HICON)GetDlgItem(IDI_ICON1));
    m_IconImageList.Add((HICON)GetDlgItem(IDI_ICON2));

    (3). My list view is m_List.
    m_List.SetImageList(&m_IconImageList, LVSIL_NORMAL);

    (4).cs_flag.Format("%d", 0);
    for (int i = 0; i < 20; i++)
    {
    if (cs_flag == 0)
    m_List.InsertItem(LVIF_TEXT | LVIF_IMAGE,i, cs_flag, 0, 0, nImage ,NULL);
    else if (cs_flag == 1)
    m_List.InsertItem(LVIF_TEXT | LVIF_IMAGE, i, cs_flag, 0, 0, nImage, NULL);
    }
    here, nImage value is 0 which is supposed to be the index of the first
    icon in the image list when cs_flag is 0; nImage value is 1 when cs_flag is 1. Question here is : Did I get the right nImage for each icon ? How can I get the nImage ?

    I am waiting for your answer. Thanks a lot.





  2. #2
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: display icons in a column of a list view control

    See my comments below IN the ocde
    Sally

    (4).

    cs_flag.Format("%d", 0);
    for (int i = 0; i < 20; i++)
    {
    if (cs_flag == 0) // use nImage instead
    m_List.InsertItem(LVIF_TEXT | LVIF_IMAGE,i, cs_flag, 0, 0, nImage ,NULL);
    else if (cs_flag == 1) // use nImage instead
    m_List.InsertItem(LVIF_TEXT | LVIF_IMAGE, i, cs_flag, 0, 0, nImage, NULL);
    }



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