How to Create a Full-Colored CListCtrl

Environment: VC++ 5.0

Additionally, if you'd like to be able to set the color for every item inside your CListCtrl you can use this derived CListCtrl .

The following example uses this CListCtrl-derived class.

 

Using the CColorListCtrl Class

You'll see how easy it is to use this control

 

I would like to thank Codeguru.com and its team for Publishing this article on their site. Please do post me any modification that will improve the code.

Downloads

Download demo project - 108 Kb


Comments

  • Can this control be added to an Excel Userform?

    Posted by horose on 03/27/2005 02:38pm

    I have an application that displays some data from an Excel spreadsheet in a format similar to the multi-column list pictured in your example. Can this control be added to an Excel Userform. If this is possible, it would be very useful to me. Howard

    Reply
  • Show selection always bug

    Posted by Legacy on 12/04/2003 12:00am

    Originally posted by: Sergey

    Bug Description:
    When the control is in "show selection always" state, and previously selected item is being deselected,the item is still shown as selected when the focus is set back to control.
    Fix:
    in function SetSel(..) change following line:
    if (SetItemState(pos, nState, LVIS_SELECTED|LVS_EX_FULLROWSELECT))

    to

    if (SetItemState(pos, nState, LVIS_SELECTED|LVS_EX_FULLROWSELECT|LVIS_FOCUSED))


    Reply
  • how to change the color of column head

    Posted by Legacy on 05/12/2003 12:00am

    Originally posted by: gengyf

    in your exa,how can i to change the color about the column head? help me
    

    Reply
  • Found a bug in ColorListCtrl.cpp

    Posted by Legacy on 04/20/2003 12:00am

    Originally posted by: Tsuyoshi Moriyama

    It becomes an infinite loop in DeleteAllItems() when you feed it only 1 column list. (100% for 1 column)
    
    

    If I'm saying wrong, please correct me.

    I found in 1 column case, actually AddItem() doesn't work well. (items can be added but CMyLParam objects not)

    As a result of it, when you do DeleteAllItems(), since the
    size of the items > 0, CListCtrl::GetItemCount() is always true. However, since CMyLParam object == NULL (not allocated), CColorListCtrl::DeleteItem(0) does nothing in each time. That way, this becomes an infinite loop.

    Here is what I tried to fix it.
    I replaced,
    [line 206 in ColorListCtrl.cpp]
    lvi.iSubItem = 1;
    with the following;
    if ( columns > 1 ) lvi.iSubItem = 1;

    This way, it's working now. In other words, the previous code assumed more than 1 columns, I guess.

    Hope this helps somebody who encountered the same situation.

    Reply
  • Populating the Column only

    Posted by Legacy on 11/11/2002 12:00am

    Originally posted by: Mark


    Per the sample code provided. How can I populate the column and COLUMN only for each header. For instance, I'd like to populate the "Item" column with Line 1, Line 2, etc. Leave the rest empty.

    Reply
  • Why don't use CListCtrl-functions? BkColor does not work!

    Posted by Legacy on 09/11/2002 12:00am

    Originally posted by: Christian

    Why you don't use the original CListCtrl-functions to modify the style of the ListCtrl, insert items, change item color and so on???

    Reply
  • Wrong Category

    Posted by Legacy on 08/12/2002 12:00am

    Originally posted by: x3r0

    I was looking for listboxes not list controls purhaps someone should put this in the correct category for CListCtrl.

    Reply
  • Minor error in InitDialog - possible correction

    Posted by Legacy on 07/26/2002 12:00am

    Originally posted by: Richrd Muller

    A loop in OnInitDialog ends with the line:
    
    

    if (pos!=LISTCTRL_ERROR) ;

    Maybe it should be:

    if (pos == LISTCTRL_ERROR)
    break;


    Reply
  • What has this to do with CListBox

    Posted by Legacy on 07/10/2002 12:00am

    Originally posted by: Jimmy Jackson

    [Comment deleted for being too banal]

    Reply
  • How to change the column head color ?

    Posted by Legacy on 04/10/2002 12:00am

    Originally posted by: JoungJin Hwang

    Please~~~~~~~~~ Helf me!!!

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Given today's threat environment and the increasing connectivity of digital infrastructures, security teams now realize that they must assume their IT environments are subject to periodic compromise. Gone are the days when preventive measures to secure the perimeter or trying to detect malware problems using signature-match technologies were enough. New practices based on an understanding of the phases of an attack, continuous threat monitoring, and rapid attack detection and remediation are necessary. This …

  • Live Event Date: May 6, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT While you likely have very good reasons for remaining on WinXP after end of support -- an estimated 20-30% of worldwide devices still are -- the bottom line is your security risk is now significant. In the absence of security patches, attackers will certainly turn their attention to this new opportunity. Join Lumension Vice President Paul Zimski in this one-hour webcast to discuss risk and, more importantly, 5 pragmatic risk mitigation techniques …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds