Click here to Skip to main content
15,305,969 members
Articles / Desktop Programming / MFC
Posted 29 Nov 2005


36 bookmarked

A Simple Reusable List Control

Rate me:
Please Sign up or sign in to vote.
3.94/5 (20 votes)
29 Nov 20052 min read
This artcile describes a simple reusable list control


I would like to thank the authors of some old articles posted in CodeProject!! I have just consolidated information from them and created a reusable class, CListCtrlEx. I hope you will enjoy using it.


  1. Editable Cells – We can make any cell of the list control editable.
  2. Combo Box – We can place a combo box in any cell of the list control.
  3. Coloring – We can give different text colors as well as background colors for individual rows of the list control.
  4. Tooltip – Tooltip support is added with this class. Currently it shows only the current text in the cells.

Image 1

Image 2

Image 3

Using the Code

Insert a list control into your dialog. Change the view style to Report. Make a member variable of type CListCtrlEx, say m_ListCtrlMyList.

Also your project should be configured to support the Unicode character set.

How to make a cell editable?

This class contains a public member function SetEditBox.

void SetEditBox(int nItemIndex_i, int nSubItemIndex_i);

It accepts the item (row) number and the subitem (column) number as parameters.


  1. If you want to make the fourth column of the third row editable, call:
    m_ListCtrlMyList.SetEditBox(2, 3); // index starts with 0
  2. If you want to make an entire row editable, call:
    m_ListCtrlMyList.SetEditBox(2, -1);

    It indicates to make all cells in the third row editable.

  3. If you want to make an entire column editable, call:
    m_ListCtrlMyList.SetEditBox(-1, 3);

    It indicates to make all cells in the fourth column editable.

How to place a combo box in a cell?

This class contains a public member function SetComboBox.

void SetComboBox(int nRow_i, int nCol_i, CStringArray& csarValues_i);

It accepts the item (row) number and the subitem (column) number and a CStringArray as parameters. The strings that should be displayed in the combo box should be filled in the CStringArray before calling this function.


CStringArray acsComboStrings;   
m_ListCtrlMyList.SetComboBox(1,2, acsComboStrings);

As in the edit box, the following combinations are also supported.

m_ListCtrlMyList.SetComboBox(-1,-1, acsComboStrings);

m_ListCtrlMyList.SetComboBox(1,-2, acsComboStrings);


The combo box is not editable. If you want to edit it, right click on the cell in which the combo box is set. An edit box will be displayed.

How to change the text color and background of an item?

The text coloring is done within the OnCustomDraw function. For assigning a particular color for a row, call the function AddColoredRow:

void AddColoredRow(int nItemIndex,
                   COLORREF colTextColor = RGB(0, 0, 0),                   
                   COLORREF colBkColor =   RGB(255, 255, 255));

It accepts the item (row) number and two COLORREF objects for the text color and the background color.




All the methods explained above should be used after inserting the necessary columns and items into the list control, if you want to see the correct results.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Shine Kumar
Web Developer
India India
Hi,this is Shine from India, working as a software engineer. I am working mainly with C++ and C#. I like to create reusable stuffs.

Comments and Discussions

QuestionHow to SetButton and handle button event? Pin
jauming19-Aug-15 5:18
Memberjauming19-Aug-15 5:18 
Questionthe control flows Pin
Member 974734316-Jan-13 22:46
MemberMember 974734316-Jan-13 22:46 
Generalthank you Pin
fast_sky25-Jun-12 0:54
Memberfast_sky25-Jun-12 0:54 
GeneralUsing the code in our commercial product Pin
Prakash Buddhiraja12-Mar-09 15:26
MemberPrakash Buddhiraja12-Mar-09 15:26 
GeneralPorted to VC6! Pin
cristitomi5-Apr-07 4:55
Membercristitomi5-Apr-07 4:55 
GeneralRe: Ported to VC6! Pin
Shine Kumar8-Apr-07 14:57
MemberShine Kumar8-Apr-07 14:57 
QuestionCan this be applied to tab bassed aplications? [modified] Pin
Androides13-Nov-06 22:53
MemberAndroides13-Nov-06 22:53 
AnswerRe: Can this be applied to tab bassed aplications? Pin
Androides16-Nov-06 4:05
MemberAndroides16-Nov-06 4:05 
AnswerRe: Can this be applied to tab bassed aplications? Pin
bambox13-May-09 23:39
Memberbambox13-May-09 23:39 
Generalcapture value in combobox Pin
Parasuraman SundarRajan6-Nov-06 23:04
MemberParasuraman SundarRajan6-Nov-06 23:04 
GeneralInsert rows Pin
pattakaraoo1126-Feb-06 22:26
Memberpattakaraoo1126-Feb-06 22:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.