Click to See Complete Forum and Search --> : CListCtrl HELL.


laiason5
May 27th, 1999, 10:20 PM
i am very severely annoyed right now. all that i want to do is insert a freakin item into a freakin listCtrl without so much freakin trouble.

this is the function that im usin to add items to my listCtrl boxes(i added controls through VC++ 6 to my list controls and they are of type CListCtrl):


CAddRecDlg dlg;
int result = dlg.DoModal();
UpdateData();
if(result == IDOK && dlg.m_textQ.GetLength() != 0 && dlg.m_textA.GetLength() != 0)
{
int i = m_listCtrl.GetItemCount();
tNode* tmp;
tmp = SelectNode(m_treeCtrl.GetSelectedItem());
tmp->Q.resize(tmp->Q.length() + 1);
tmp->A.resize(tmp->A.length() + 1);
tmp->Q[tmp->Q.length() - 1] = dlg.m_textQ;
tmp->A[tmp->A.length() - 1] = dlg.m_textA;
m_listCtrl.InsertItem(i, dlg.m_textA);
CString t = m_listCtrl.GetItemText(i,0); //this always returns a null string
m_listCtrl2.InsertItem(i, dlg.m_textA);

m_listCtrl.SetItemText(i,0,"Test"); //always gives debug assertion failure and i comment out to get it to run
//

}
}



tNode is simple a structure that i created and has nothing to do with the listCtrl

this is how my lists are initialized(with OnInitDlg() ):


CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

if(!myRoot.NodeName) //Lists are initialized here:
{
CRect bounds;
m_listCtrl.GetWindowRect(bounds);
myRoot.NodeName = m_treeCtrl.InsertItem(CString("MyList"));
m_treeCtrl.SelectItem(myRoot.NodeName);
m_listCtrl.InsertColumn(0, CString("Questions:"), LVCFMT_LEFT, bounds.Width(),0);
m_listCtrl2.InsertColumn(0, CString("Answers:"), LVCFMT_LEFT, bounds.Width(),0);
Invalidate();
}

// TODO: Add extra initialization here

return TRUE; // return TRUE unless you set the focus to a control
}




as you can see, ive added columns and everything
but every time i try to run(in report view... i can get it to run in list view mode but it still doesnt add anything) it gives me a debug assertion failure.

the set item text always flags a debug assertion failure and if i let it run through to system dll's it gives me one also. can someone plz help me?

thanks for the time
L5

sally
May 28th, 1999, 12:59 AM
Try this:


const int ind = m_listCtrl.InsertItem(i, dlg.m_textA);
CString t = m_listCtrl.GetItemText(ind,0); //this always returns a null string
m_listCtrl.SetItemText(ind,0,"Test"); //always gives debug assertion failure and i comment out to get it to run




Sally

Sally
May 28th, 1999, 12:59 AM
Try this:


const int ind = m_listCtrl.InsertItem(i, dlg.m_textA);
CString t = m_listCtrl.GetItemText(ind,0); //this always returns a null string
m_listCtrl.SetItemText(ind,0,"Test"); //always gives debug assertion failure and i comment out to get it to run




Sally

Paul Burns
May 28th, 1999, 01:34 AM
m_listCtrl.SetItemText(i,0,"Test");

this line will definitely cause you grief cause 'i' is the count of items in the control, which +1 above last index (item indexes are zero based).

Paul Burns
May 28th, 1999, 01:41 AM
sorry, wasn't paying attention. i just noticed the InsertItem call you have preceding SetItemText.

What exactly does SetItemText assert on, i.e. what's mfc complaining about?