如何在C ++运行时将.csv数据读入对话框 [英] How to read the .csv data into dialog box at run time in C++

查看:69
本文介绍了如何在C ++运行时将.csv数据读入对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们执行对话框时,数据无法显示在编辑控件中打开.csv文件后。



主要要求是:



当我们更新.csv文件中一次显示的列(即@Run时间)时,对话框中显示的结果将被更改。



我尝试了什么:



我试图在给定的编辑框中显示字符串并使用以下内容示例代码:



Data cant be displayed in edit control when we are execute the dialog box After opening the .csv file.

Main Requirement is:

the result which are showing in Dialog box will be changed when we updates the columns which are presented in .csv file at a time (i.e @Run time).

What I have tried:

Am trying to display the strings in given edit boxes with using following sample code:

CStdioFile file;            // access the entire given file
CString cstrLine, Temp;     // Reading the entire row at a time from excel sheet

if (file.Open(L"Data.csv", CFile::shareExclusive | CFile::typeText))    // L ---- 
                                                                      //Multybyte type
{

  while (file.ReadString(cstrLine))
  Temp = cstrLine;
  cstrLine = Temp;         // Reading the last Row every time

  int i = 0;

  for (CString sItem = cstrLine.Tokenize(_T(","), i); i >= 0; sItem = 
                                                       cstrLine.Tokenize(_T(","), i))
  {
	sItem.Trim();  // For trimming extra spaces
	str.Add(sItem);
  }

  m_csName = str.GetAt(0);  //0 means Column 1,s data
  m_csSurName = str.GetAt(1); // 1 means Column 2's data    /* of particular row in 
                                                             Excel sheet */ 
  m_csAge = str.GetAt(2); // 2 means Column 3's data

  UpdateData(FALSE); // Variable 2 Control

  file.Close();
}





但我想要以下要求:即



当我们一次更新.csv文件中显示的列(即@Run时间)时,对话框(在编辑框中)显示的结果将被更改。



But I want following requirement: i.e.,

"the result which are showing in Dialog box (In Edit Boxes) will be changed when we updates the columns which are presented in .csv file at a time (i.e @Run time)."

推荐答案

据我所知,您的问题是观察文件中的更改,而不是刷新应用程序中的数据。我看到可能的解决方案,最简单的是你安装一个计时器,它检查文件的最后修改时间而不是反应。



但更优雅的是观察文件或目录的变化。在Microsoft文章

获取目录更改通知
不仅描述了,还描述了一些示例代码如何实现。我还会检查上次修改时间以避免执行更新。



在退出时清理所有手柄非常重要!!!
As I understand your problem is to observe the file for changes and than refresh the data in your app. I see to possible solutions with the simplest that you install a timer which check the last modified time of the file and than reacts.

But more elegant is to observe the file or directory for changes. In the Microsoft article
Obtaining Directory Change Notifications
is not only described but also some sample code how it can be implemented. I also would check the last modified time to avoid excess execution of the update.

It is very important to cleanup all handles at exit!!!


这篇关于如何在C ++运行时将.csv数据读入对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆