CListCtrl m_StudentInfo;
下面的代码:
for(int i=0;i<10;i++)
{
LVITEM lvitem;
lvitem.mask=LVIF_TEXT;
lvitem.iItem=i;
lvitem.iSubItem=0;
CString str;
str="hello";
lvitem.pszText=(LPTSTR)(LPCTSTR)str;
m_StudentInfo.InsertItem(&lvitem);
}
为何不能插入字符串到listcontrol中,第一次使用这个控件,大家帮帮忙
下面的代码:
for(int i=0;i<10;i++)
{
LVITEM lvitem;
lvitem.mask=LVIF_TEXT;
lvitem.iItem=i;
lvitem.iSubItem=0;
CString str;
str="hello";
lvitem.pszText=(LPTSTR)(LPCTSTR)str;
m_StudentInfo.InsertItem(&lvitem);
}
为何不能插入字符串到listcontrol中,第一次使用这个控件,大家帮帮忙
lvitem.pszText=(LPTSTR)(LPCTSTR)str;
===========================================================
lvitem.pszText="hello";CString str;
是局部变量,会提前被释放
m_StudentInfo.InsertColumn(0, "name",LVCFMT_LEFT,100);