listcontrol的问题 ,请求解
class A
{
public:
CListCtrl m_worklist;//控件变量
void InsertPatientInfoItem(int id,CString Pname);
};
void A::InsertPatientInfoItem(int id,CString Pname)
{
int nIndex = m_worklist.GetItemCount();//在这里抛异常
LV_ITEM lvItem;
lvItem.mask = LVIF_TEXT ;
lvItem.iItem = nIndex;
lvItem.iSubItem = 0;
CString temp ;
temp.Format("%d",id);
lvItem.pszText = (char*)(LPCTSTR)temp;
m_worklist.InsertItem(&lvItem);
m_worklist.SetItemText(nIndex,1,Pname);
}
class B
{
public:
A *mwork;
void Add();
};
void B::Add() //想在listcontrol里面插入一行信息
{
mwork->InsertPatientInfoItem(1,'zhangshan');
}
就是想在listcontrol加入一行信息,可是用B类对象去执行A类里面的listcontrol ,总是抛异常。
如果是A类对象去执行A类里面的listcontrol ,则没问题。