如何在Visual Studio中的MFC中的ListControl中显示所选文件名

How to display the selected file name in the ListControl in MFC in Visual Studio?

本文关键字:中的 显示 文件名 ListControl MFC Visual Studio      更新时间:2023-10-16

我使用列表控件创建了一个网格函数。列表中有两列。数据和名称。

用户应选择一个文件;文件内的数据应显示在第一列"data"中,文件名应显示在第二列"name"中。我已经写了一个代码,但列表中没有出现任何内容

CFileFind finder;
bool bFound;
CString filename = "C:\ Location\*.txt";
bFound = finder.FindFile(filename);
if(bFound) 
{
   while(bFound) 
   {
        bFound = finder.FindNextFile();
        if(bFound)
        {
            m_List.AddString(finder.GetFileName()); //This is where the actual data is added 
        }
   }
   CStdioFile files;
   CFileException exp;
   CString strLine;  
   if (files.Open(filename, CFile::modeRead, &exp))
   {
      while(files.ReadString(strLine)){}
   }
}
void CuserspecificationDlg::InsertItems()
{
       HWND hWnd = ::GetDlgItem(m_hWnd, IDC_LIST1);
       // Set the LVCOLUMN structure with the required 
       // column information
         ..
         .. 
         SetCell(hWnd,out,1,1);   // where out is the Cstring variable for edit control  
}

可能是什么错误?

请参阅此处的列表框使用教程。您可以定义一个CListBox类型的成员变量,该变量通过控件向导映射到您的列表框。