Scrollbars and CListCtrl

I am working with CListCtrl window which has only one column, but I
really need to suppress appearance of horizontal scroll bar. I tried
to modify window style to remove WS_HSCROLL, but seems that MFC
overrides me. For now I am suppressing it by loading data, getting
client rectangle and setting column width to client rectangle width.
Unfortunately this fails with PocketPC WinMobile 5. There
GetClientRect seems to return rectangle that includes scrollbar. This
adds a problem of now finding the width of vertical scrollbar,
solution to which is not obvious to me. 

There must be a better way to suppress horizontal scrollbar in
CListCtrl. Can someone please point me at it, or at least tell me how
to programatically find scroll bar width in CListCtrl.

Thanks,
Henryk Birecki
0
5/11/2007 8:07:10 AM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
2202 Views

Similar Articles

[PageSpeed] 51

"Henryk Birecki" <soaringpilot@sbcglobal.net> wrote in message 
news:oe8843du21vepsrlvhkb3evg496nbt0sa8@4ax.com...
>I am working with CListCtrl window which has only one column, but I
> really need to suppress appearance of horizontal scroll bar. I tried
> to modify window style to remove WS_HSCROLL, but seems that MFC
> overrides me. For now I am suppressing it by loading data, getting
> client rectangle and setting column width to client rectangle width.
> Unfortunately this fails with PocketPC WinMobile 5. There
> GetClientRect seems to return rectangle that includes scrollbar. This
> adds a problem of now finding the width of vertical scrollbar,
> solution to which is not obvious to me.
>
> There must be a better way to suppress horizontal scrollbar in
> CListCtrl. Can someone please point me at it, or at least tell me how
> to programatically find scroll bar width in CListCtrl.
>

The horizontal scrollbar does not appear if all the columns fit without 
needing to be scrolled.  Since there is only one column, all you have to do 
is resize that column so that it is the exact width of the client area.  To 
do that:

   MyListCtrl.SetColumnWidth (0, LVSCW_AUTOSIZE_USEHEADER);

-- David


0
dc2983 (3206)
5/11/2007 9:05:43 AM
You said it has only one column.  Just make sure the width of this column is <= the width
of the client area of the control.  If GetClientRect is returning the wrong width, you
could subtract off ::GetSystemMetrics(SM_CXVTHUMB) [if I remember the name correctly,
check GetSystemMetrics) which is the width of the  vertical scrollbar thumb.
					joe

On Fri, 11 May 2007 08:07:10 GMT, Henryk Birecki <soaringpilot@sbcglobal.net> wrote:

>I am working with CListCtrl window which has only one column, but I
>really need to suppress appearance of horizontal scroll bar. I tried
>to modify window style to remove WS_HSCROLL, but seems that MFC
>overrides me. For now I am suppressing it by loading data, getting
>client rectangle and setting column width to client rectangle width.
>Unfortunately this fails with PocketPC WinMobile 5. There
>GetClientRect seems to return rectangle that includes scrollbar. This
>adds a problem of now finding the width of vertical scrollbar,
>solution to which is not obvious to me. 
>
>There must be a better way to suppress horizontal scrollbar in
>CListCtrl. Can someone please point me at it, or at least tell me how
>to programatically find scroll bar width in CListCtrl.
>
>Thanks,
>Henryk Birecki
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
5/11/2007 2:29:30 PM
"David Ching" <dc@remove-this.dcsoft.com> wrote:

>"Henryk Birecki" <soaringpilot@sbcglobal.net> wrote in message 
>news:oe8843du21vepsrlvhkb3evg496nbt0sa8@4ax.com...
>>I am working with CListCtrl window which has only one column, but I
>> really need to suppress appearance of horizontal scroll bar. I tried
>> to modify window style to remove WS_HSCROLL, but seems that MFC
>> overrides me. For now I am suppressing it by loading data, getting
>> client rectangle and setting column width to client rectangle width.
>> Unfortunately this fails with PocketPC WinMobile 5. There
>> GetClientRect seems to return rectangle that includes scrollbar. This
>> adds a problem of now finding the width of vertical scrollbar,
>> solution to which is not obvious to me.
>>
>> There must be a better way to suppress horizontal scrollbar in
>> CListCtrl. Can someone please point me at it, or at least tell me how
>> to programatically find scroll bar width in CListCtrl.
>>
>
>The horizontal scrollbar does not appear if all the columns fit without 
>needing to be scrolled.  Since there is only one column, all you have to do 
>is resize that column so that it is the exact width of the client area.  To 
>do that:
>
>   MyListCtrl.SetColumnWidth (0, LVSCW_AUTOSIZE_USEHEADER);
>
>

Thanks. This actually works in all cases. Somewhat surprising as I do
not use header row. Just using LVSCW_AUTOSIZE also suppressed
scrollbar, but left space between column and vertical scrollbar. Would
not be really a problem, but I am using whole column width selection
indicator.

Henryk Birecki
0
5/12/2007 12:37:35 AM
Reply:

Similar Artilces:

Differnce between CListBox and CListCtrl and CListView
Hi Can someone tell me the difference between CListBox, CListCtrl and CListView classes. When to do for which class? Which class will be suitable for creating multicolumn list? Thanks in advance, Vijay > Can someone tell me the difference between CListBox, CListCtrl and > CListView classes. When to do for which class? > Which class will be suitable for creating multicolumn list? CListCtrl is used on a Dialog or Property Page. It is something you drag and drop and size it up the way you want automatically. CListView is used within a view. You have to tell it where to position ...

Overriding CListCtrl/CListView
Hello I have the following problem. I have to write few classes based on CListView which load some data from database. Those classes should contain interface to manage the data. I would like to make accessible functions like Load - which loads all the data from database, Clear - deletes all the data from database and respectively from ListCtrl, Delete - deletes all selected entries from ListView and from database, etc. The interface is used by CMyDialog class, which contains buttons to execute those actions by user and of course List Control which is the graphical representation of the data c...

Virtual CListCtrl crashes when clicked on in MFC code
Hi, I've written an application with a standard CListCtrl (non-virtual), it was working fine (inserting, deleting, sorting the columns, etc.). Because it got to slow when more and more data piled up i changed the code so that it's a virtual list now (OWERNDATA). But now strange things happen: Most of the time (but not always) the program crashes, when I click on the list after having filled it's content twice (=reloaded the content). Everything else is working after start-up. I can sort, I can scroll, etc. But after reloading the content (list.SetItemCount(0); refilling my array;...

Item height in CListCtrl
Is possible to set height of items in CListCtrl created without LV_OWNERDRAWFIXED style ? Peter I think you need owner drawn http://www.codeproject.com/listctrl/changerowheight.asp I don't know if this would work if you force some newlines at the end of the strings to make the rows taller... http://www.codeproject.com/listctrl/MultilineListControl.asp Tom "Peter" <Peter@discussions.microsoft.com> wrote in message news:85B91E43-9C32-4D32-9B8A-E21E9DCB9D30@microsoft.com... > Is possible to set height of items in CListCtrl created without > LV_OWNERDRAWFIXED styl...

Settem
Hi I created a report list control that initially fills the first column on all its rows and leaves the next two columns blank. Now I want to write code that will allow me to fill in the "blanks" at a variable row, column When I use SetItem (Without insert item) nothing is filled in. How do I code for this? Thanks in Advance >I created a report list control that initially fills the first column on all >its rows and leaves the next two columns blank. > >Now I want to write code that will allow me to fill in the "blanks" at a >variable row, column >When ...

bolding an item in a CListCtrl
Hi, I would like to bold one of the items in a list control (using CListCtrl of MFC). How is this done? Any pointers, source code or advice will be appreciated. Thanks, Jeremy. You should be able to do it using NM_CUSTOMDRAW. I did the same thing for a tree control using customdraw. It gives you the ability to change font of each item among other things. Sample for handling customdraw is available at codeguru and MSDN. -- Ajay Kalra [MVP - VC++] ajaykalra@yahoo.com "Jeremy Pullicino" <removeallunderscores_jeremy_p_@_gfi__._com__> wrote in message news:eSktIps9DHA.19...

Editing in CListCtrl (report mode)
I have a list control where the cells are editable, where the intention is you can edit the cells in column 1 but not in column 0 (a kind of properties list control) But I can't stop the user from holding down the left button for a long time and then editing in that cell. I have trapped the LVN_ENDLABELEDIT so it does not apply the change for column 0 but it is still untidy? Any ideas? No worries, i've realised I just don't call the OnLButtonDown for the parent class if in column 0. I always realise the answer just after ive posted. "Chris Baker" wrote: > ...

2 CListCtrl with one hor. scrollbar
Hello, I've two listctrl with same coloumns & same col-width. i need a function to scroll list2 with list1 scrollbar. Jimmy On Sun, 10 Sep 2006 15:51:24 +0200, Johann Obermayr <Johann.Obermayr@fastrun.at> wrote: >Hello, > >I've two listctrl with same coloumns & same col-width. >i need a function to scroll list2 with list1 scrollbar. > > Jimmy Handle WM_HSCROLL and WM_VSCROLL as necessary and forward the messages to the 2nd list control. To keep the controls in sync, you will also have to watch keyboard navigation; for example, paging down doe...

Excel 2007 Scrollbars
Right click and choose bottom. The scrollbar goes to the bottom but the displayed region doesn't change until the mouse is put at the bottom of the scrollbar and clicked. Any fix for this bug? If so, where do we download a service pack from? Thanks ...

CListCtrl and view with splitter
How does one create a dialog-type application that is split with the top 3/4 of the window a CListCtrl subclassed object and the bottom 1/4 of the window a plain CDialog pane split by a splitter bar that can be adjusted. Any code snippets would be helpful. thanks chris I just wrote this code yesterday. Since it is not proprietary, and in fact I plan to publish it in a variety of public source code forums, send me private and email and I'll send you a copy. Some of the details will vary from what you ask for, but the rest of the code is trivial. It took me about a half-hour to write a...

Need help with CListCtrl
Using CListCtrl, but when I sort the indexes do not go along with the records. Here's what I mean: Suppose I add these items: Row 0: John Row 1: Bob Row 2: Tom Now when I click on the header and sort them in alphabetical order: Row 1: Bob Row 0: John Row 2: Tom Now when I call GetItemData(0) I am expecting to get "John". 0 is where I added "John". But instead, I get "Bob" (the new sort ordered index). So this presents a problem. I have no idea where John is anymore.. in case I wanted to edit that item later, I have to scan through all the items. You...

CListCtrl and WinXP features sample?
Hi I am trying to make use of the "tile view" and grouping features of the list-view control under XP, using VS.net 2003 I created anf MFC app, checked the "common controls manifest" option in the wizard, redefined the OS and IE version makros to 0x0501, and tried to create groups and enable the group view and/or switch to the tile view. Unfortunately, all I can achieve is the standard look of the list view control Strangely, I cannot find any sample demonstrating the use of CListCtrl::InsertGroup() and/or CListCtrl::SetView (LV_VIEW_TILE) If anyone worked it out before, c...

Given a pointer to a CListCtrl can I get the control ID/name?
Given a pointer to a CListCtrl can I get the control ID/name? All, I have a generic function which takes a pointer to a CListCtrl, I want to be able to programmatically tell which control I am working on. Is there anyway I can query the resource name or something which will give me this? PT Paul Tomlinson wrote: > Given a pointer to a CListCtrl can I get the control ID/name? > > All, I have a generic function which takes a pointer to a CListCtrl, I want > to be able to programmatically tell which control I am working on. Is there > anyway I can query the resource na...

CListCtrl problem #4
I have CListCtrl control (Icon style, single selection) in my CDialog with assigned CImageList image list and everything works ok except when I select an item: the text of that item is there but the image is gone??? Of course, when control loses focus the image is restored back. What am I missing? Thanks for help... //code snippet int i=0; LVITEM item; item.iItem=i; item.iImage=0; item.mask=LVIF_TEXT|LVIF_IMAGE; while(some condition){ item.iItem=i; item.iSubItem=0; item.pszText=_T("some text..."); item.iImage=i; ((CListCtrl*)GetDlgItem(IDC_LIST))-&...

Scrollbars skining
Hello, Im trying to find a method to skin scrollbars of any control in my application process. I tried this method: i am using a CBT hook and on creation of some specific types of controls i subclass them. So i have my own window procedure. On this im trying to create and position a top static window over the control scrollbars. the static control is a sibling one with the control(have the same parent). The thing is the method is errorneous and it doesnt work for example, for a ComboLBox control (a list box created by combobox control). I found a tutorial which uses detours library, by API h...

CListCtrl with LVS_REPORT, trouble setting font
I'm getting unpredictable behaviour when setting the font on a list control. I'm trying to reduce the font size so that I can make more columns visible. No matter what I try the font is bigger than when I started and BOLD. If I use this code CFont* pFont = m_lvPaths.GetFont(); m_lvPaths.SetFont(pFont); my list control text is bigger and bolder, but I've not changed anything? Unless the font used is different to the one returned by m_lvPaths.GetFont(); Anyone know what's going on here? "ropo" <ARopson@yahoo.co.uk> wrote in message news:1190119159.095236.9...

Removing a window's frames does not remove it from the scrollbar
I have a dialog box with a tree control that will automatically holds a scrollbar. In the dialog's OnInitDialog I load the tree with so much content that the tree automatically creates a vertical scrollbar. I want to remove the tree's frame, but when I do the frame is removed from everything except the scrollbar. It isn't until I move the mouse over the scrollbar (causing it to highlight) or force the bar to scroll that the frame will disappear. I have tried invalidating and repainting the tree but that does not help. I have even dragged the dialog box offscreen and pull...

CListCtrl's GridLine question
hi,everyone. My Application want use CListView to show Data with Grid style. So I create ,and put the CListCtl's style as follow: cs.style |= LVS_REPORT | LVS_EX_GRIDLINES; .. But the Grid line don't show . why? In fact, as this example so many in internet ,but I can't resolve this problem. Anyone get me out. Thank you in advance! LVS_EX_GRIDLINES is an extended style. Try the following in your view's OnInitialUpdate() function. void CYourListView::OnInitialUpdate() { CListView::OnInitialUpdate(); CListCtrl& listCtrl = GetListCt...

problem with CListCtrl
Hi all I have created a list view control using CViewCtrl of MFC .I also apply sorting in list view . Now when I tried to change any entry of coloum one of listView then it makes duplicate entry , mean two entries by same name ..Although there is no duplicate entry in the file where the items of list view are stored , there is only one entry , but in list view itself it shows two entries untill i reopen the application again . Any help amit bharadwaj VC++(ATL,MFC) developer Not sure exactly because you cannot show any code. But I do know that if you add items to a list based clas...

controlling icon drawing in CListCtrl
hi there i have implemented a CListCtrl which displays graphic images as normal icons i have created for each item in the list several images relating to unselected, selected, drophilited, and hover states, and have written the code to update the image item index when the appropriate events occur all is going well, except i have one last 'issue' i would like resolve - when an item is selected in LVS_ICON mode in a CListCtrl, the icon's text is painted white on blue, and the icon has some kind of 'mask' applied to it to appear selected - i would like to prevent the icon ...

Nasty ScrollBar
I have created CView derived class. When some items are added to view in run-time and place in view is not sufficient it display scrollbar - all is OK. I need to display scrollbar always, not only when place is not sufficient. How to do it ? I have tried: m_view->ShowScrollBar(SB_VERT); m_view->EnableScrollBar(SB_VERT); but it does not help. Thanks ! Peter I think you need to have a non-zero range for the scrollbar. I have this vague memory that if the range is zero, the scrollbar won't show. It has been a very long time since I did a view that required a scrollbar, so I'm a...

Owner draw in CListCtrl
Hi, I would like to create an owner draw CListCtrl in thumbnail mode. Can somebody please help me by giving some pointers in doing this. I have done owner draw list controls for the detail view, But for the icon view, I am very much confused. Some articles or code sample would be really helpful. Looking forward for a reply. Thanks and Regards San http://www.codersource.net/mfc_gdi_plus_thumbnail_clistctrl.html -- With Regards, Selvam http://www15.brinkster.com/selvamselvam/ "San" wrote: > Hi, > > I would like to create an owner draw CListCtrl in thumbnail mod...

Smart CListCtrl column sizing
Hi, I was wondering, is there an easy way to make the column sizing of this control smarter? For example, after you insert items for the first time, it should resize a column so all items fit, unless that'd cause a scrollbar to be required. The same should happen after items are inserted. SetColumnWidth(i, LVSCW_AUTOSIZE_USEHEADER); could be used, but that'd be a bit slow because it'd iterate through all items every time. And is there a way to submit feature requests for MFC to MS? Because I'd like to see smarter behaviour not just in my app, but in all other apps (includ...

CListCtrl.GetNextSelectedItem doesnot seem to work.
Hi, I am trying to use this code from msdn to get the list of selected rows in the container of the CListCtrl (multi select mode). It works fine if the user selects 2 rows. But for more that that, it doesnot work. "pos" will point to NULL after two rows. MSDN code: ========= POSITION pos = pList->GetFirstSelectedItemPosition(); if (pos == NULL) //TRACE0("No items were selected!\n"); else { while (pos) { int nItem = pList->GetNextSelectedItem(pos); //TRACE1("Item %d was selected!\n", nItem); // you could do your own processing on ...

Scrollbars inside CMainFrame
Hello, I'm using a MDI application. I've added scrollbars to the mainframe inside the PreCreateWindow() function, cs.style |= WS_VSCROLL | WS_HSCROLL; This works fine, only after resizing (for zooming) or moving my CViews 'outside' the mainframe, the scrollbars don't resize automatically (only if I scroll around or resize my mainFrame). I've already tried several things like RepositionBars or RecalcLayout, both seems to have no effect. How can I make the scrollbars recalculate their positions and size? Thanks in advance, Arno ...