horizontly scroll my headers, when I scroll my listbox using the scroll bar of the listbox

Posted on 1998-08-27
Last Modified: 2010-04-15
I am adding columnar data to a listbox with fixed pitch font. Now I need to put headers to describe the columns. How do I horizontly scroll my headers, when I scroll my listbox using the scroll bar of the listbox?
Question by:rferrell

Accepted Solution

emmons earned 100 total points
ID: 1252331
1: This should be in the Windows section, not the C section.
2: If you add a handler for scroll message in the list box, and then send a scroll message to the header whenever the body scrolls, you should be able to keep them in synch.


Expert Comment

ID: 1252332
My alternative solutions

1. Switch to ListView control (CListCtrl in MFC) if using 32 bit windows.  This may unfortunately avoid some significant code rewriting


2. Make the listbox owner draw (LBS_OWNERDRAWFIXED style) and handle the WM_DRAWITEM messages

In Draw item test if the item being drawn is the top visible line, if it is draw the headers instead of the real item.  You will loose a line from the listbox as a result of this, so insert extra dummy items.

This isn't a very good solution but can be made to work reasonably well.


3. Create a header control above the listbox (i.e. don't actually put the headers in the list).  When you scroll the list box, update the header control to match

#1 or #3 are the best solutions in my view, and involve the least code.  If you are in Win32 you really should consider #1 as the ListView control is much better for this kind of thing than the ListBox.


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Microsoft vcsetup.exe and vcssetup.exe 8 413
Can case within switch statement specify range of values ? 3 76
Computer slow / BSOD 10 43
Why isn't object file created? 6 42
This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now