Solved

How to embed a CListCtrl into a CView in a Doc-View Arch

Posted on 2000-03-27
13
529 Views
Last Modified: 2013-11-20
Hi again....

I have a Doc-View architecture where a want to have a CListView as the child view, but I want to use a CListCtrl derived class because I want to manage some events and other functions of the CListCtrl embedded in the CListView class. It didn0t work, so I'm trying using CView instead of CListView and then to show my custom CListCtrl. This is my CView class:

int CVistaMarcas::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
      if (CView::OnCreate(lpCreateStruct) == -1)
            return -1;

      RECT rect;
      rect.bottom = rect.left = rect.right = rect.top = 0;
      m_ListaMarcas.Create(LVS_REPORT|LVS_AUTOARRANGE|LVS_SINGLESEL|LVS_NOSCROLL, rect, this, IDC_LISTAMARCAS);
      return 0;
}

void CVistaMarcas::OnSize(UINT nType, int cx, int cy)
{
      CView::OnSize(nType, cx, cy);
      
      CRect rect;
      GetWindowRect(&rect);
      m_ListaMarcas.MoveWindow(rect, FALSE);
      m_ListaMarcas.SetColumnWidth(0, 13*rect.Width()/100);
      m_ListaMarcas.SetColumnWidth(1, rect.Width()/5);
      m_ListaMarcas.SetColumnWidth(2, rect.Width()/5);
      m_ListaMarcas.SetColumnWidth(3, rect.Width()/5);
      m_ListaMarcas.SetColumnWidth(4, 27*rect.Width()/100);
}

void CVistaMarcas::OnInitialUpdate()
{
      CView::OnInitialUpdate();
      
      m_ListaMarcas.InsertColumn(0, "Nodo");
      m_ListaMarcas.InsertColumn(1, "Fecha");
      m_ListaMarcas.InsertColumn(2, "Hora");
      m_ListaMarcas.InsertColumn(3, "PIN");
      m_ListaMarcas.InsertColumn(4, "Movimiento");
}

void CVistaMarcas::OnSetFocus(CWnd* pOldWnd)
{
      CView::OnSetFocus(pOldWnd);
      
      m_ListaMarcas.SetFocus();      
}

Where m_ListaMarcas is my custom CListCtrl class.... How can I show m_ListaMarcas?

Thanks a lot in advance
Skel
0
Comment
Question by:skel
  • 5
  • 2
  • 2
  • +3
13 Comments
 
LVL 8

Expert Comment

by:VinExpert
ID: 2660526
Hi,

After creating it, use

m_ListaMarcas.ShowWindow(SW_SHOW);

VinExpert
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2660576
HI skel,

try to add WS_CHILD|WS_VISIBLE styles when creating...

ZOPPO
0
 

Author Comment

by:skel
ID: 2662334
It didn't work.... neither m_ListaMarcas.ShowWindow(SW_SHOW) nor m_ListaMarcas.Create(LVS_REPORT|LVS_AUTOARRANGE|LVS_SINGLESEL|LVS_NOSCROLL|WS_CHILD|WS_VISIBLE, rect, this, IDC_LISTAMARCAS)

Do you suggest something else to test? are the other parameters correct? (rect, this and IDC_LISTAMARCAS)

Thanks
Skel
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 8

Expert Comment

by:VinExpert
ID: 2662715
Hi,

See here is the working code
In OnCreate(...)

m_cFileDetailsLV.Create(
            WS_VISIBLE | WS_CHILD | LVS_LIST | LVS_EDITLABELS |
                LVS_AUTOARRANGE | LVS_SHAREIMAGELISTS , // styles
            CRect(0,0,0,0),      // bounding rectangle,
            this, //parent
            ID_LISTVIEW); //id

In OnSize()

m_cFileDetailsLV.MoveWindow(0, 25, cx, cy);

And in OnInitialUpdate(...) I am also inserting the columns, And it is working fine. But, there is a list control object on the view which is placed using resource editor. I think U can try that way.

VinExpert
0
 
LVL 4

Expert Comment

by:captainkirk
ID: 2665048
you might want to use CFormView instead of CView...
0
 

Accepted Solution

by:
mmg earned 100 total points
ID: 2667969
CRect rect;
GetClientRect(&rect); //Set the control's initialize size

m_ListaMarcas.Create(WS_VISIBLE | WS_CHILD|LVS_REPORT|LVS_AUTOARRANGE|LVS_SINGLESEL|LVS_NOSCROLL, rect, this, IDC_LISTAMARCAS);
0
 

Author Comment

by:skel
ID: 2668927
Hi... hmm.. it continue not working..... that CListCtrl isn't shown.... I'm wondering whether it is possible to display a CListCtrl in a CView... and I don't want to use CFormView instead because that way an ugly black frame is shown, or when I create the CFormView in resource editor at least..

In my case, I assigned to IDC_LISTAMARCAS a value of 1001 which isn't used by any other resource

Any further help will be greately appreciated


Skel
0
 

Author Comment

by:skel
ID: 2668936
Is it necesary to use ShowWindow? In what method I have to place it?

Thanks
0
 
LVL 3

Expert Comment

by:SamHobbs
ID: 2675784
It is certainly possible to use CListCtrl in a CView. Did my reply to your CodeGuru post help? As I said there, I have a program that puts a CListCtrl in a CView. Here is the relevant portion of my view's OnCreate:


      RECT Rect=CFrameWnd::rectDefault;
      DWORD dwStyle, dwCommonStyles=WS_CHILD|WS_VISIBLE|WS_BORDER;
if (CView::OnCreate(lpCreateStruct) == -1)
      return -1;
dwStyle = dwCommonStyles | LVS_REPORT | LVS_SORTASCENDING;
if (!m_Container.Create(dwStyle, Rect, this, IDC_FIELDS))
      return -1;


One thing that is important to uderstand is that a CListView is essentially a CListCtrl. If you look at the source MFC for CListView you will see that there is not much of it. Were you using CListView::GetListCtrl? Did you generate your application using AppWizard and with CListView specified for a view?

0
 
LVL 3

Expert Comment

by:SamHobbs
ID: 2675785
I wish they woudl do something about the formatting of code in thsi web site. My code was formatted better before being mangled by this web site.
0
 

Author Comment

by:skel
ID: 2675894
I have discovered the following.....

In the CVistaMarcas OnInitialUpdate I insert data to the CListCtrl and that data appears on the screen.... so the CListCtrl is there but the Column headers isn't displayed... do I have a missing style?

I'm using CView instead of CListView...

Thanks
Skel
0
 

Author Comment

by:skel
ID: 2675910
My application is SDI and m_ListaMarcas is a CListCtrl derived class

Skel
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2679112
Perhaps it would help if you add to the view's styles the WS_CLIPCHILDREN style...
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

829 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