Click here to Skip to main content
11,716,938 members (83,978 online)
Click here to Skip to main content

Hide scrollbars from a CListCtrl

, 1 Jul 2003 CPOL 153.6K 1.7K 34
Rate this:
Please Sign up or sign in to vote.
Removes the scrollbars from a CListCtrl without loosing the ability to scroll
<!-- Article image -->

Sample Image - ListCtrlSBHide.jpg

<!-- Add the rest of your HTML here -->

Introduction

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!

Background

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
public:
    CCListCtrlExampleDlg(CWnd* pParent = NULL);    // standard constructor

    //These are the defs for each type of how we hide the scrollbars
// Dialog Data
    //{{AFX_DATA(CCListCtrlExampleDlg)
    enum { IDD = IDD_CLISTCTRLEXAMPLE_DIALOG };
    CListCtrlHiddenSB    m_list4;
    CListCtrlHiddenSB    m_list3;
    CListCtrlHiddenSB    m_list2;
    CListCtrlHiddenSB    m_list1;
    //}}AFX_DATA

    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CCListCtrlExampleDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL
//(...)

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

m_list1.HideScrollBars(LCSB_CLIENTDATA, SB_VERT);
m_list2.HideScrollBars(LCSB_CLIENTDATA);
m_list3.HideScrollBars(LCSB_NCOVERRIDE);
m_list4.HideScrollBars(LCSB_NCOVERRIDE);

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.

History

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

License

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

Share

About the Author

Lars [Large] Werner
Engineer
Norway Norway
I'm looking for new opportunities in Norway, contact me on email, twitter or Facebook
Not able to travel (a lot) so either home office or in Telemark area, Norway.

----------------------------------
Visit http://lars.werner.no/ for my techno-blog!
----------------------------------

Projects
* Adito - Simple Windows installer for Adito/OpenVPN ALS!
* Unpacker - Auto extract of multiple archives (RAR/ZIP) with queue support and cleanup options!
* SizeMe - Ultimate tool for maximize your output on CD/DVDs!

You may also be interested in...

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
Nataraj S.15-Mar-04 19:43
sussNataraj S.15-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
memberLars [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
memberLars [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
memberLars [Large] Werner3-Jan-04 19:41 
GeneralHeight is not correct Pin
Nguyen Tuan Quang14-Dec-03 16:31
memberNguyen Tuan Quang14-Dec-03 16:31 
GeneralRe: Height is not correct Pin
Lars [Large] Werner14-Dec-03 19:24
memberLars [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
memberLars [Large] Werner6-Oct-03 9:44 
GeneralScrollbar of CListCtrl Pin
Anonymous10-Sep-03 3:57
sussAnonymous10-Sep-03 3:57 
GeneralRe: Scrollbar of CListCtrl Pin
<marquee>Lars [Large] Werner</marquee>10-Sep-03 8:13
memberLars [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
memberLars [Large] Werner1-Jul-03 22:30 
GeneralRe: another way to hide scroll bars Pin
glip1-Jul-03 23:03
memberglip1-Jul-03 23:03 
GeneralRe: another way to hide scroll bars Pin
Lars [Large] Werner1-Jul-03 23:11
memberLars [Large] Werner1-Jul-03 23:11 
GeneralRe: another way to hide scroll bars Pin
glip2-Jul-03 1:26
memberglip2-Jul-03 1:26 
GeneralRe: another way to hide scroll bars Pin
Lars [Large] Werner2-Jul-03 1:28
memberLars [Large] Werner2-Jul-03 1:28 
GeneralRe: another way to hide scroll bars Pin
Magnus Houska21-Sep-03 5:54
sussMagnus Houska21-Sep-03 5:54 
GeneralRe: another way to hide scroll bars Pin
<marquee>Lars [Large] Werner</marquee>21-Sep-03 6:12
memberLars [Large] Werner21-Sep-03 6:12 
GeneralRe: another way to hide scroll bars Pin
sudhakar_Chavali8-Jan-04 1:38
susssudhakar_Chavali8-Jan-04 1:38 
GeneralRe: another way to hide scroll bars Pin
sudhakar_Chavali8-Jan-04 1:39
susssudhakar_Chavali8-Jan-04 1:39 
GeneralRe: another way to hide scroll bars Pin
Lars [Large] Werner8-Jan-04 1:46
memberLars [Large] Werner8-Jan-04 1:46 
GeneralRe: another way to hide scroll bars Pin
Jung Jinhyuck28-May-04 1:57
memberJung Jinhyuck28-May-04 1:57 
GeneralRe: another way to hide scroll bars Pin
Ted Pederson4-Apr-05 9:07
sussTed Pederson4-Apr-05 9:07 
Generalnice Pin
Matthias Hänel29-Jun-03 12:59
memberMatthias Hänel29-Jun-03 12:59 
GeneralRe: nice Pin
Lars [Large] Werner30-Jun-03 11:45
memberLars [Large] Werner30-Jun-03 11:45 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150901.1 | Last Updated 2 Jul 2003
Article Copyright 2003 by Lars [Large] Werner
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid