Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 572
  • Last Modified:

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

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
skel
Asked:
skel
  • 5
  • 2
  • 2
  • +3
1 Solution
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

After creating it, use

m_ListaMarcas.ShowWindow(SW_SHOW);

VinExpert
0
 
ZoppoCommented:
HI skel,

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

ZOPPO
0
 
skelAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Vinayak KumbarSr Program ManagerCommented:
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
 
captainkirkCommented:
you might want to use CFormView instead of CView...
0
 
mmgCommented:
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
 
skelAuthor Commented:
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
 
skelAuthor Commented:
Is it necesary to use ShowWindow? In what method I have to place it?

Thanks
0
 
SamHobbsCommented:
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
 
SamHobbsCommented:
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
 
skelAuthor Commented:
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
 
skelAuthor Commented:
My application is SDI and m_ListaMarcas is a CListCtrl derived class

Skel
0
 
ZoppoCommented:
Perhaps it would help if you add to the view's styles the WS_CLIPCHILDREN style...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now