Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm going to post one more time with more detail.
Visual Studio C++ 2008.

I have tried a CListCtrl inside a dialog as well as a CListView derived project.
I can populate the control with data if it's in list mode and the data appears, if I try to use the report view of the control. I create the columns and they appear in the top of the control as expected.

However, when I add an item to the control, the reported count increases, I can retrieve the text data, however, I cannot see the data, it is not visible. I have tried all the usual things. I have tried both methods of adding an item, the LVITEM structure and just the plain a string. Neither works. Once again, the control is aware of the item being added. I can even fetch the item's string back and it appears to be right, but the data does not appear in the control

I even tried to force the text and background color but to no avail.

I have used this same method in the past on other projects and I have not had this trouble however that was with Studio 2003 and Studio 2005.

Am I missing something simple here or is this a real issue. I have all three projects if anyone is interested in settings.
Posted
Comments
Jibesh 5-Feb-13 20:21pm    
can you paste the code so that i can try the same in my PC.
william basser 6-Feb-13 11:11am    
// TestListViewView.cpp : implementation of the CTestListViewView class
//

#include "stdafx.h"
#include "TestListView.h"

#include "TestListViewDoc.h"
#include "TestListViewView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CTestListViewView

IMPLEMENT_DYNCREATE(CTestListViewView, CListView)

BEGIN_MESSAGE_MAP(CTestListViewView, CListView)
ON_COMMAND(ID_EDIT_TEST, &CTestListViewView::OnEditTest)
ON_COMMAND(ID_VIEW_LIST, &CTestListViewView::OnViewList)
ON_COMMAND(ID_VIEW_DETAILS, &CTestListViewView::OnViewDetails)
END_MESSAGE_MAP()

// CTestListViewView construction/destruction

CTestListViewView::CTestListViewView()
{
// TODO: add construction code here

}

CTestListViewView::~CTestListViewView()
{
}

BOOL CTestListViewView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style &= ~LVS_TYPEMASK;
cs.style |= LVS_REPORT;

return CListView::PreCreateWindow(cs);
}

void CTestListViewView::OnInitialUpdate()
{
CListView::OnInitialUpdate();

CListCtrl &listTest = GetListCtrl( );
CHeaderCtrl* phdrTest = listTest.GetHeaderCtrl( );

// create a item
HDITEM hdiItem;
hdiItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
hdiItem.cxy = 150;
hdiItem.fmt = HDF_STRING | HDF_LEFT;
hdiItem.pszText = _T( "Column1" );
phdrTest->InsertItem( 0, &hdiItem );
hdiItem.pszText = _T( "Column2" );
phdrTest->InsertItem( 1, &hdiItem );
}


// CTestListViewView diagnostics

#ifdef _DEBUG
void CTestListViewView::AssertValid() const
{
CListView::AssertValid();
}

void CTestListViewView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}

CTestListViewDoc* CTestListViewView::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestListViewDoc)));
return (CTestListViewDoc*)m_pDocument;
}
#endif //_DEBUG


// CTestListViewView message handlers

void CTestListViewView::OnEditTest()
{
// get the list contro
CListCtrl &listTest = GetListCtrl( );

// fill
CString strTemp;
for ( int i = 0; i < 50; i++ )
{
strTemp.Format( _T( "Test: %d" ), i );
listTest.InsertItem( i, strTemp );
strTemp.Format( _T( "Col2: %d" ), i );
listTest.SetItemText( i, 1, strTemp );
}


UpdateData( false );
}

void CTestListViewView::OnViewList()
{
// TODO: Add your command handler code here
LONG lStyle = GetWindowLong( m_hWnd, GWL_STYLE );
lStyle &= ~LVS_TYPEMASK;
lStyle |= LVS_LIST;
SetWindowLong( m_hWnd, GWL_STYLE, lStyle );
}

void CTestListViewView::OnViewDetails()
{
// TODO: Add your command handler code here
LONG lStyle = GetWindowLong( m_hWnd, GWL_STYLE );
lStyle &= ~LVS_TYPEMASK;
lStyle |= LVS_REPORT;
SetWindowLong( m_hWnd, GWL_STYLE, lStyle );
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900