Click here to Skip to main content
13,835,258 members
Click here to Skip to main content
Add your own
alternative version


3 bookmarked
Posted 13 Dec 2018
Licenced CPOL

MFC CListEx - List Control with Tooltip Ability.

, 12 Jan 2019
Rate this:
Please Sign up or sign in to vote.
List control with cells tooltiping ability, and even more.


When I first faced a necessity in List Control with the ability to show tooltips on individual cells, I was discouraged with the fact that such obvious feature simply doesn’t exist in standard MFC CListCtrl.

Well, apparently, it’s time to implement it.

Long Story Short

CListEx is a CMFCListCtrl derived class with cell’s tooltip ability. And even more.
It works with LVS_OWNERDRAWFIXED and LVS_REPORT styles. The tooltiping is achieved with public method:

void SetCellTooltip(int iItem, int iSubitem, const std::wstring& strTooltip, 
                    const std::wstring& strCaption = { });

With this method, you can set a tooltip for any cell (item/subitem), that will show up on mouse hovering. Tooltips are implemented as Windows balloons. 

To remove tooltip from cell just set it again with empty string (L"").

Control was built and tested in Visual Studio 2017.


  1. Add two files in your project: ListEx.h and ListEx.cpp.
  2. #include "ListEx.h"
  3. Control uses its own namespace, so either type: using namespase LISTEX, or use LISTEX:: prefix when declaring CListEx variable: LISTEX::CListEx myList;

To set a tooltip for a given cell, just write:

myList.SetCellTooltip(0, 1, L"Tooltip", L"Tooltip caption:");

This will set a tooltip for cell (0, 1) with text: "Tooltip", and caption "Tooltip caption".

But It’s Not Yet It

Additionally, in CListEx::Create method, there is one additional parameter - pointer to LISTEXINFO struct. This parameter goes last so it doesn’t break compatibility with the existing code, you can simply change the class of your existing CListCtrl members to CListEx.

What's Inside

The LISTEXINFO is a helper structure which fields are described below:

typedef struct LISTEXINFO {
    COLORREF clrListText;          //List text color.
    COLORREF clrListBkRow1;        //List Bk color for odd rows.
    COLORREF clrListBkRow2;        //List Bk color for even rows.
    COLORREF clrListGrid;          //List grid color.
    DWORD dwListGridWidth;         //Width of the list grid.
    COLORREF clrListTextSelected;  //Selected item text color.
    COLORREF clrListBkSelected;    //Selected item bk color.
    COLORREF clrTooltipText;       //Tooltip window text color.
    COLORREF clrTooltipBk;         //Tooltip window bk color.
    COLORREF clrListTextCellTt;    //Text color of cell that has tooltip.
    COLORREF clrListBkCellTt;      //Bk color of cell that has tooltip.
    const LOGFONT* pListLogFont;   //List font.
    COLORREF clrHeaderText;        //List header text color.
    COLORREF clrHeaderBk;          //List header bk color.
    DWORD dwHeaderHeight;          //List header height.
    const LOGFONT* pHeaderLogFont; //List header font.

Every member of this struct has its default value, so you don’t have to worry about filling them all, only the fields you are about to customize.

With this structure alone and with additional methods, you can tune a plethora of list’s aspects:

  • Color of the list text and bk (background). Bk is set separately for odd and even rows
  • Color of the list header
  • Height of the list header
  • Font of the list header, and font of list itself
  • Color of individual header's columns
  • Color of tooltip's window text and bk
  • Color of the text and bk of a cell that has tooltip
  • Color of list grid, and even its width
  • Color of row when it's selected

Public Methods

CListEx class also has a set of additional public methods to help customize your control in many different aspects.    

void SetFont(const LOGFONT* pLogFontNew);
void SetFontSize(UINT uiSize);
UINT GetFontSize();
void SetTooltipColor(COLORREF clrTooltipText, COLORREF clrTooltipBk,
        COLORREF clrTextCellTt,                         //Text color of a cell that has tooltip.
        COLORREF clrBkCellTt);                          //Bk color of a cell that has tooltip.
void SetHeaderColor(COLORREF clrHdrText, COLORREF clrHdrBk);
void SetHeaderHeight(DWORD dwHeight);
void SetHeaderFont(const LOGFONT* pLogFontNew);
void SetHeaderColumnColor(DWORD nColumn, COLORREF clr); //Sets the color for arbitrary header column.


Let’s imagine that you need a list control with a non standard header height, and yellow background color.
Nothing is simpler, just write:

listInfo.dwHeaderHeight = 50;
listInfo.clrListBkRow1 = RGB(255, 255, 0);
listInfo.clrListBkRow2 = RGB(255, 255, 0);
CListEx myList;
myList.Create(WS_CHILD | WS_VISIBLE, CRect(0, 0, 800, 400), this, 0x1, &listInfo);

Here, we set both - even and odd rows (clrListBkRow1 and clrListBkRow2) to the same yellow color.


With the Ctrl+MouseWheel combination you can dynamically change list's font size.

Licencing and Contribution

You can use this code for free with the only condition — to provide the link back to the Author, in the form of:


  • 22nd December, 2018 - v1.2 Added SetHeaderColumnColor method
  • 5th January, 2019 - v1.3 Small fixes
  • 13th January, 2019 - v1.4 Many improvements and fixes. Dynamic font sizing added.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Russian Federation Russian Federation
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionCan not work on a Dialog Pin
suhm7723-Dec-18 21:49
membersuhm7723-Dec-18 21:49 
AnswerRe: Can not work on a Dialog Pin
Jovibor24-Dec-18 0:47
memberJovibor24-Dec-18 0:47 
GeneralRe: Can not work on a Dialog Pin
suhm7724-Dec-18 4:41
membersuhm7724-Dec-18 4:41 
GeneralRe: Can not work on a Dialog Pin
Jovibor24-Dec-18 13:00
memberJovibor24-Dec-18 13:00 
GeneralRe: Can not work on a Dialog Pin
suhm7724-Dec-18 22:00
membersuhm7724-Dec-18 22:00 
QuestionSome Enhancements Pin
Rick York19-Dec-18 7:55
mveRick York19-Dec-18 7:55 
AnswerRe: Some Enhancements Pin
Jovibor19-Dec-18 12:17
memberJovibor19-Dec-18 12:17 
GeneralRe: Some Enhancements Pin
Rick York19-Dec-18 13:15
mveRick York19-Dec-18 13:15 
GeneralRe: Some Enhancements Pin
Jovibor19-Dec-18 14:41
memberJovibor19-Dec-18 14:41 
SuggestionFeature Suggestion Pin
Rick York15-Dec-18 9:02
mveRick York15-Dec-18 9:02 
GeneralRe: Feature Suggestion Pin
Jovibor15-Dec-18 12:46
memberJovibor15-Dec-18 12:46 
GeneralRe: Feature Suggestion Pin
Jovibor16-Dec-18 13:56
memberJovibor16-Dec-18 13:56 
GeneralRe: Feature Suggestion Pin
Rick York16-Dec-18 18:03
mveRick York16-Dec-18 18:03 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.190114.1 | Last Updated 13 Jan 2019
Article Copyright 2018 by Jovibor
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid