Click to See Complete Forum and Search --> : Help...annoyed beginner about to go postal


laiason5
May 31st, 1999, 10:08 AM
i have posted on the forum for the past week and so far have not gotten any suggestions that work. all i need to do is get this **** list control to add items to the display and it refuses to do it. every time i add an item to it, it sets the item text to null(i.e. "").if i try to set the item text, it gives a debug assertion failure. Here below is the code for the SetItemText function of CListCtrl. It gives a debug assertion in this line:

BOOL CListCtrl::SetItemText(int nItem, int nSubItem, LPCTSTR lpszText)
{
ASSERT(::IsWindow(m_hWnd));
ASSERT((GetStyle() & LVS_OWNERDATA)==0); //This causes debug assertion failure(or at least thats what the debugger tells me
LVITEM lvi;
lvi.iSubItem = nSubItem;
lvi.pszText = (LPTSTR) lpszText;
return (BOOL) ::SendMessage(m_hWnd, LVM_SETITEMTEXT, nItem, (LPARAM)&lvi);
}




my list controls are initialized and accessed like this:

CListCtrl m_listCtrl2; //this is in my header
CListCtrl m_listCtrl; //this is in my header

DDX_Control(pDX, IDC_LIST2, m_listCtrl2);//this is in DoDataExchange(...), it initializes it i think
DDX_Control(pDX, IDC_LIST, m_listCtrl);//this is in DoDataExchange(...), it initializes it i think

//These are in my OnInitDlg(...)
m_listCtrl.InsertColumn(0, CString("Questions:"), LVCFMT_LEFT, bounds.Width(),0);
m_listCtrl2.InsertColumn(0, CString("Answers:"), LVCFMT_LEFT, bounds.Width(),0);

//this is how im adding to my List

int i = m_listCtrl.GetItemCount(); //first time through returns 0
m_listCtrl.InsertItem(i, dlg.m_textQ);//works as far as i can tell
CString t = "Test"; //test string init
t = m_listCtrl.GetItemText(1,0); //t's value goes from "Test" to ""
m_listCtrl.SetItemText(i, 0, dlg.m_textQ); //must comment out to run(or i get debug assertion failure)
i = m_listCtrl.GetItemCount(); //this returns 1 instead of 0 so i have added the item




i have been working forever on this and any help would be great. i think that i have included all references to my CListCtrl variables so if you dont see something in here, it wasnt added by me to the code. so... HELP!!!

thanks
L5

laiason5
May 31st, 1999, 10:19 AM
BTW, my list control is in report view mode.

June 1st, 1999, 04:55 AM
This thing isn't a edit box where you can add text at your whim.

Don't know what the dlg.m_TextQ for variable is but I suspect that it is a CString or a char*
You need to use a LV_ITEM (or LVI_ITEM, don't have docs on hand atm)

you need to set the mask of this item to LV_TEXT (or LVI_TEXT)
then add the text to the item
then insert the item

srini_raghav
June 1st, 1999, 07:11 AM
In a listcontrol using ReportView mode, the first column in all the rows is the item which u can select rest is only for display if u don't use full row selection...
If so, the first column, means 0 th column shd be added using InsertItem and not by using setItem text. U r trying to add like this for 0th column. SetItemText(i,0,CString). Try this and let me know...
Thanks lot,
Srini

BrianOG
June 1st, 1999, 10:22 AM
Check the settings for the control in th resource editor, and turn off OwnerDraw (cause this means that you will do the drawing). You only want that if you need something CListCtrl cant handle.

laiason5
June 1st, 1999, 10:59 PM
that annoys me that i spent over week trying to figure it out and it was fixed by deselecting one little checkbox. thanks.

BrianOG
June 2nd, 1999, 01:49 AM
Well the line it was asserting on, was trying to ensure that this style was turned off.
When you get an assertion in the MFC code it is generally for a good reason. And if the assertion itsself does not provide some clues to the problem, debugging up to the assert should provide you with the asnwer (in most cases).