2012-09-24 47 views
-1

我想从如何在列表视图

文本文件

列表视图和树视图中显示的数据显示文本文件的数据。根将文件名,但我不知道如何做到这一点,问题是在列表视图中显示文本文件数据,我不知道任何关于这一点。 文本文件中的数据是非常简单的 它像双值只是一个方阵:

21.06 34.06 5.0

12.78 45.25 6.9

12.89 45.98 5.5

列表查看我想要显示它。

回答

1

读取文本文件

listBox1->Items->Clear(); 
    try 
    {  
     String* textFile = String::Concat(windir,(S"\\mytest.txt"));        
      StreamReader *reader=new StreamReader(textFile); 
     do 
     { 
      listBox1->Items->Add(reader->ReadLine()); 
     } 
     while(reader->Peek() != -1); 
    }  

    catch (System::Exception *e) 
    { 
     listBox1->Items->Add(e); 
    } 

} 

查看文件信息

listBox1->Items->Clear(); 
String* testfile = String::Concat(windir, (S"\\notepad.exe")); 
FileInfo *pFileProps =new FileInfo(testfile); 

listBox1->Items->Add(String::Concat(S"File Name = ", (pFileProps->get_FullName()))); 
listBox1->Items->Add(String::Concat(S"Creation Time = ", (pFileProps->get_CreationTime()).ToString())); 
listBox1->Items->Add(String::Concat(S"Last Access Time = " ,(pFileProps->get_LastAccessTime()).ToString())); 
listBox1->Items->Add(String::Concat(S"Last Write Time = ", (pFileProps->get_LastWriteTime()).ToString())); 
listBox1->Items->Add(String::Concat(S"Size = ", (pFileProps->get_Length()).ToString())); 

欲了解更多信息请参阅HERE

对于树查看您可以按照这个page

+0

我已经用于这个目的的资源管理器,我的意思是我没有拖放列表框,所以会有什么替代?在这种情况下使用上面的代码 – tspga