Re: Display a CListCtrl in a CScrollView

From: Scott McPhillips [MVP] (org-dot-mvps-at-scottmcp)
Date: 08/26/04


Date: Wed, 25 Aug 2004 19:17:01 -0500

Richard Rauch wrote:

> Hello All,
>
> I created a CScrollView (as pane from a CSplitterWnd, perhaps that's the
> problem?)
> In this view, I want to display a CListCtrl. But the ListCtrl is not
> displayed. Why not?
> Perhaps the nID in the Create Call is the problem, I do not unterstand, what
> the parameter is for!
>
> I wrote this code:
>
> void CPaneView::OnInitialUpdate()
> {
> CScrollView::OnInitialUpdate();
> CSize sizeTotal;
> // TODO: calculate the total size of this view
> sizeTotal.cx = sizeTotal.cy = 100;
> SetScrollSizes(MM_TEXT, sizeTotal);
>
> CListCtrl m_List;
>
> CRect rect(0,0,sizeTotal.cx,sizeTotal.cy);
> m_List.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|LVS_LIST,rect,this,1);
>
> LV_COLUMN lvC;
> lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
> // Insert Columns and Items
> .....
> m_List.ShowWindow(SW_SHOW);
>
>

It looks like you are doing the wrong thing and doing it the wrong way.
  The "wrong way" part is that your m_List object is created on the
stack. Therefore it will be destroyed when OnInitialUpdate returns. To
make this work m_List will have to be a member variable.

But you almost certainly should to use CListView or CFormView instead of
CScrollView. Use CFormView if you want the list at a fixed size, and/or
if you want to put other controls on this view. Use CListView if you
want the list to fill the view pane when things are resized. In either
case, the list control will be created for you by the view: You don't
need to create it dynamically.

The nID parameter is the control's ID. When the control sends you
messages they include the control's ID. That is how your code (or MFC's
class wizard and message map) will know which control the message came from.

-- 
Scott McPhillips [VC++ MVP]


Relevant Pages

  • Re: Display a CListCtrl in a CScrollView
    ... Have you tried using a CListView instead of a CScrollView. ... will scroll for you as well and it will fill the whole pane. ... Tom ... I want to display a CListCtrl. ...
    (microsoft.public.vc.mfc)
  • Re: Layer JPanels ?
    ... control. ... I tried putting all 3 JPanels in a single JPanel, and adding this to the content pane. ... forces JPanels to display on top of each other? ...
    (comp.lang.java.gui)
  • Re: Validating ComboBox Entries
    ... To prevent a user from entering any data, it can't be in the rowsource. ... still need to see it in the employees historical entries. ... the project name is displayed in the Combo control. ... I would have to display a Message Box or something similar to ...
    (microsoft.public.access.formscoding)
  • RE: VS2005 DataList with Nested GridView using ObjectDataSource
    ... you're wantting to display some data on the ASP.NET ... web page through the DataList control, and since those data records can ... category items in the DataList and in each DataList item, use a GridView ... | customer number in a grid (call it QUERY A). ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Object creation
    ... I thought that I could easily copy a single Excel file from ... I've built my userform and got some of the code running. ... display the link names accordingly. ... range of 3 columns and then show that in my control. ...
    (microsoft.public.excel.programming)