Click here to Skip to main content
15,073,154 members
Articles / Desktop Programming / MFC
Posted 25 Jun 2003


36 bookmarked

Hide scrollbars from a CListCtrl

Rate me:
Please Sign up or sign in to vote.
3.36/5 (21 votes)
1 Jul 2003CPOL1 min read
Removes the scrollbars from a CListCtrl without loosing the ability to scroll

Sample Image - ListCtrlSBHide.jpg


When you create a CListCtrl with the "NO SCROLL" option it completely stop scrolling. If the data is out of the screen you do not see anything. So you always had to use the scrollbars - until now!


I used this on many kiosk software solutions, and it gives you complete control of the CListCtrl. 

Using the Code

The CListCtrlHiddenSB is derived from CListCtrl.

It has one function to hide the scrollbars: HideScrollBars(int Type, int Which)

The type variable has two const: LCSB_CLIENTDATA and LCSB_NCOVERRIDE

The Which variable tells which scrollbar that will be hidden, here we use the default: SB_BOTH, SB_HORZ and SB_VERT.

Clientdatatype of hiding scrollbars must be called BEFORE any data is entered, because this will change the clientrect of the ctrl to be smaller.

In the demo project I override the normal constructor, like this:

class CCListCtrlExampleDlg : public CDialog
// Construction
    CCListCtrlExampleDlg(CWnd* pParent = NULL);    // standard constructor

    //These are the defs for each type of how we hide the scrollbars
// Dialog Data
    CListCtrlHiddenSB    m_list4;
    CListCtrlHiddenSB    m_list3;
    CListCtrlHiddenSB    m_list2;
    CListCtrlHiddenSB    m_list1;

    // ClassWizard generated virtual function overrides
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

Just before the listctrl's are filled with data we hide the scrollbars:

m_list1.HideScrollBars(LCSB_CLIENTDATA, SB_VERT);

Known Issues

If you have an listctrl that will just get a horiz-scrollbar, and you choose to hide both of the scrollbars. The function will also remove the vert-scrollbar, but since it is not there some of the gfx will be cut off.

In other words, the clientarena should only be used when you KNOW how many of the scrollbars that will be shown.

Personally I prefer using the NcCalcSize. It removes the scrollbars pretty smooth. It's not dependent on whether or not the listctrl shows all scrollbars or not.


First release - Version 1.0. It will be updated when more solutions are found...


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


About the Author

Lars [Large] Werner
Engineer A/S Norske Shell (Dutch Shell)
Norway Norway
Visit for my blog!
Retired programmer, Norway never had the jobs I wanted Smile | :)

Comments and Discussions

QuestionGood One Pin
MANISH RASTOGI19-Jul-11 19:26
MemberMANISH RASTOGI19-Jul-11 19:26 
Generala problem about CListCtrlHiddenSB Pin
followait7-Jul-08 0:41
Memberfollowait7-Jul-08 0:41 
GeneralThanx Pin
Denis Lazarev23-Jun-07 8:06
MemberDenis Lazarev23-Jun-07 8:06 
GeneralIt does work for NT Systems but not for CE Pin
Nataraj197815-Mar-04 19:43
MemberNataraj197815-Mar-04 19:43 
GeneralRe: It does work for NT Systems but not for CE Pin
GDavy11-May-04 3:10
MemberGDavy11-May-04 3:10 
GeneralRe: It does work for NT Systems but not for CE Pin
Summer June23-May-05 21:26
MemberSummer June23-May-05 21:26 
QuestionHow to Remove Scrollbar Controls form CFormView Pin
Sudhakar_Chavali8-Jan-04 1:31
sussSudhakar_Chavali8-Jan-04 1:31 
AnswerRe: How to Remove Scrollbar Controls form CFormView Pin
Lars [Large] Werner8-Jan-04 1:36
professionalLars [Large] Werner8-Jan-04 1:36 
GeneralRe: How to Remove Scrollbar Controls form CFormView Pin
Koundinya8-Jan-04 1:55
MemberKoundinya8-Jan-04 1:55 
GeneralRe: How to Remove Scrollbar Controls form CFormView Pin
Koundinya8-Jan-04 2:00
MemberKoundinya8-Jan-04 2:00 
AnswerRe: How to Remove Scrollbar Controls form CFormView Pin
mjw128-Jul-04 15:16
Membermjw128-Jul-04 15:16 
GeneralRe: How to Remove Scrollbar Controls form CFormView Pin
Lars [Large] Werner28-Jul-04 17:50
professionalLars [Large] Werner28-Jul-04 17:50 
GeneralRe: How to Remove Scrollbar Controls form CFormView Pin
ccsilence6-Jan-10 2:05
Memberccsilence6-Jan-10 2:05 
GeneralVery nice. Pin
Neal.Liu3-Jan-04 19:38
MemberNeal.Liu3-Jan-04 19:38 
GeneralRe: Very nice. Pin
Lars [Large] Werner3-Jan-04 19:41
professionalLars [Large] Werner3-Jan-04 19:41 
GeneralHeight is not correct Pin
QuangNT14-Dec-03 16:31
MemberQuangNT14-Dec-03 16:31 
GeneralRe: Height is not correct Pin
Lars [Large] Werner14-Dec-03 19:24
professionalLars [Large] Werner14-Dec-03 19:24 
GeneralRe: Height is not correct Pin
Igorn2-Mar-04 12:22
MemberIgorn2-Mar-04 12:22 
GeneralRe: Height is not correct Pin
nthroot18-May-06 17:52
Membernthroot18-May-06 17:52 
GeneralAdditionnal explanations Pin
Stlan5-Oct-03 22:27
MemberStlan5-Oct-03 22:27 
GeneralRe: Additionnal explanations Pin
Lars [Large] Werner6-Oct-03 9:44
professionalLars [Large] Werner6-Oct-03 9:44 
GeneralScrollbar of CListCtrl Pin
Anonymous10-Sep-03 3:57
MemberAnonymous10-Sep-03 3:57 
GeneralRe: Scrollbar of CListCtrl Pin
Lars [Large] Werner10-Sep-03 8:13
professionalLars [Large] Werner10-Sep-03 8:13 
Generalanother way to hide scroll bars Pin
glip1-Jul-03 20:39
Memberglip1-Jul-03 20:39 
GeneralRe: another way to hide scroll bars Pin
Lars [Large] Werner1-Jul-03 22:30
professionalLars [Large] Werner1-Jul-03 22:30 

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.