Before I start, please excuse any mistakes I make in nomenclature. I am a beginner at this MFC stuff.

I am writing a transaction server and trying to use CListView to display the status of the multiple client threads I've got going. I've got it to where the columns of my list view are displaying, but when I add an item, it does not display. The following code adds an item to my list. As you can see by my commented out lines, I have tried many things to get the item to display, but none has worked. I know that this function is executing because my "In OnAddNewPort" log entry is showing up. I feel like there is just one little thing I am overlooking. Can you help? Please let me know if there is further information or code I can post that would help you to help me.


void CTServListView::OnAddNewPort(WPARAM nPortIndex, LPARAM lParam)
//	int* pnPort;
	char szPort[8];
//	CMainFrame* pFrm = reinterpret_cast<CMainFrame*>(AfxGetApp()->GetMainWnd());
	CListCtrl& theListCtrl = GetListCtrl();

	CString szMsg;
	szMsg.Format("In OnAddNewPort %d", nPortIndex);
	g_Logger->LogBasic(szMsg, nPortIndex, LOG_DEBUG);
//	pnPort = (int *)pnPortIndex;

	sprintf(szPort, "%d", nPortIndex + 1);

	theListCtrl.InsertItem(nPortIndex, szPort);
	theListCtrl.SetItemText(nPortIndex, SUBITEM_PORT, szPort);
	theListCtrl.SetItemText(nPortIndex, SUBITEM_CALLS, "0");
	theListCtrl.SetItemText(nPortIndex, SUBITEM_TXNS, "0");
	theListCtrl.SetItemText(nPortIndex, SUBITEM_FAILURES, "0");
	theListCtrl.SetItemText(nPortIndex, SUBITEM_LAST_TRANS, "");
	theListCtrl.SetItemText(nPortIndex, SUBITEM_LAST_MESSAGE, "");

//	theListCtrl.Update(nPortIndex);
//	theListCtrl.RedrawItems(0, nPortIndex);
//	theListCtrl.Invalidate();
//	theListCtrl.Update(nPortIndex);
//	theListCtrl.UpdateWindow();
//	pFrm->UpdateWindow();

Never mind - I found the problem and it had nothing to do with the code I sent in my post. I was trying to call the function from the wrong message map.

This article has been dead for over six months. Start a new discussion instead.