?
Solved

Nothing showing in CListView

Posted on 1998-03-09
1
Medium Priority
?
264 Views
Last Modified: 2013-11-20
Ok, I have a view in my application which is derived from CListView.  Unfortunetly, when I add items to the view, nothing shows up.  The client area remains blank, although resizing the window make scroll bars appear which make it seem like the items are there.  In any case, here is the pertinent code:
/* here is the creation handler...it should be in report view with no column headers */
BOOL CMessageView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
      dwStyle |= LVS_REPORT | LVS_NOCOLUMNHEADER | LVS_SINGLESEL;
      return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}

/*here is the code which inserts an item into the view */
/*my purpose here is to insert the item as the last thing in the control, then scroll down to make sure it can be seen */
void CMessageView::PostMessage(CString str, BOOL mode)
{
      CListCtrl &ctrl = GetListCtrl();
      if (mode == TRUE)
      {
            ctrl.InsertItem(ctrl.GetItemCount(), str.GetBuffer(500));
            ctrl.InsertItem(ctrl.GetItemCount(), "-");
            ctrl.EnsureVisible(ctrl.GetItemCount(), FALSE);
      }
      else
      {
            ctrl.InsertItem(ctrl.GetItemCount(), str.GetBuffer(500));
            ctrl.EnsureVisible(ctrl.GetItemCount(), FALSE);
      }
}

so there it is...very simple. I thought I'd like to at least get the text going before I added a CImageList to it.  Anyone have any idea why it isn't drawing?
0
Comment
Question by:openGL
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 11

Accepted Solution

by:
mikeblas earned 280 total points
ID: 1316850
Your code doesn't create any columns. You need to  call CListCtrl::InsertColumn() at least once.

Your code shouldn't call str.GetBuffer() like it does; that's entirely bogus.  Just pass str directly and let the implicit conversion operator take over:

  ctrl.InsertItem(ctrl.GetItemCount(), str);

.B ekiM
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

800 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