0

Case: I'm working on engine controlling software that shows all measured parameters in datagridview. The parameters are measured in one second interval so that the datagridview add new row every one second. I've done that task by using a timer.

Problem: I need to save all the data from datagridview in CSV format every time new row added.

I could achieve this by writing the save task in the timer. But it is a too heavy process for my computer in the control room. It is too heavy because the task I've implemented needs to create the file, open it, read all the data, write it, and close the file. I only need to write/add the new row to the file. Moreover, I can't use a button.

I need the save task will automatically executed every time a new row added.

I've tried to search the solution from the internet and I can't find the best one for my case. I need a lightweight solution.

  • Why are you making the solution more complicated. Write the CSV in timer at same time data is added to the DGV – jdweng Jul 25 '20 at 07:50
  • Refer to this https://stackoverflow.com/questions/4959722/c-sharp-datatable-to-csv for Datatable to CSV – zia khan Jul 25 '20 at 07:55
  • @jdweng I've edited my question. Sorry. – Stanley Siahaan Jul 25 '20 at 08:02
  • @ziakhan I've read it. it used a loop, and not adding only the new row to the file. Thanks btw. – Stanley Siahaan Jul 25 '20 at 08:06
  • Ok so when you update your datagridview source, also update CSV at that time like jdweng said. Also see https://stackoverflow.com/questions/47468750/how-to-add-new-rows-into-the-existing-csv-file-without-affecting-existing-rows – zia khan Jul 25 '20 at 08:10
  • Open the file on application start with FileMode.Append. When the timer ticks, write one line to an already opened file. Also set AutoFlush to true. On app exit/crash close the file. – Alexander Petrov Jul 25 '20 at 11:25

0 Answers0