Visual studio 2010 在visualstudio中如何在MFC的列表控件中动态存储?
我正在visual studio 2010中使用MFC开发基于对话框的应用程序。我使用列表控件作为报告类型来显示。我设法在输出窗口上显示了一些硬编码的数据。这是代码。代码中有什么错误Visual studio 2010 在visualstudio中如何在MFC的列表控件中动态存储?,visual-studio-2010,visual-c++,mfc,listcontrol,Visual Studio 2010,Visual C++,Mfc,Listcontrol,我正在visual studio 2010中使用MFC开发基于对话框的应用程序。我使用列表控件作为报告类型来显示。我设法在输出窗口上显示了一些硬编码的数据。这是代码。代码中有什么错误 void CuserspecificationDlg::OnAdd() // This function add file by clicking on Add button { // TODO: Add your control notification handler code here
void CuserspecificationDlg::OnAdd() // This function add file by clicking on Add button
{
// TODO: Add your control notification handler code here
CFileDialog ldFile(TRUE);
// Show the File Open dialog and capture the result
if (ldFile.DoModal() == IDOK)
{
CStdioFile fileName;
//TCHAR buf[100]; // it is declared in h file
while( fileName.ReadString(buf,99))
{}
fileName.Close();
}
void CuserspecificationDlg::InsertItems()
{
//
list.cx = 100;
list.pszText = "Project"; // this project is the column heading of the dialog
list.iSubItem = 2;
::SendMessage(hWnd ,LVM_INSERTCOLUMN,
(WPARAM)1,(WPARAM)&list);
SetCell(hWnd,"1",0,0);
SetCell(hWnd,buf,0,1); // these 1,G,X,X are the hardcoded entries.
SetCell(hWnd,"G ",0,2);
SetCell(hWnd," X",0,3);
//-----//
}
如何显示那个buf?它不起作用。buf未正确地从文件中删除内容。由于某些字符1、G和X在输出窗口中可见,但buf语句不能正确显示这些字符。。代码中有什么错误 要向列表控件添加项,首先需要创建列:
LVCOLUMN lvCol;
lvCol.mask = LVCF_TEXT | LVCF_WIDTH;
lvCol.pszText = L"Column Header Text";
m_CListCtrl.InsertColumn(0, &lvCol);
// ...
然后将项插入struct typeLVITEM
LVITEM item;
item.mask = LVIF_TEXT;
item.pszText = "Column Text";
item.iItem = numItem; // Item number
item.iSubItem = 0; // Sub item number (column number)
m_CListCtrl.InsertItem(&item);
这个东西我已经在我的原始程序中声明过了。正确阅读问题please@Nabeel:
“这个东西我已经声明了”
。什么“东西”?项目属于什么类型?它当然没有在代码段中声明。上面的示例是向列表控件添加项的基本方法。你需要在“它不起作用”这一点上进行扩展;我已经在我的原始程序中声明了,但没有粘贴到这里。我对设置单元格功能有问题。。我希望现在天气转晴