如何在Visual Studio中的MFC列表控件中动态存储?

时间:2012-07-17 10:58:00

标签: 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
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语句未正确显示字符。 ..代码中有什么问题。

1 个答案:

答案 0 :(得分:0)

要将项目添加到列表控件,首先需要创建一个列:

LVCOLUMN lvCol;
lvCol.mask = LVCF_TEXT | LVCF_WIDTH;
lvCol.pszText = L"Column Header Text";
m_CListCtrl.InsertColumn(0, &lvCol);

// ...

然后将项插入结构类型LVITEM

的列表控件中
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);
相关问题