Hi Masters,
I have few doubts in windows forms, i was imported txt file in tabpage with data gridview and also i have some modification done in that data grid view so now i want to save the data in same file name with same location where i imported
So please give advice with some examples
thank you
Abhishek YadavPosted Jul 18, 2024, 3:25 AM
Saving Modified Data from DataGridView Back to the Text File in Windows Forms
To save the modified data in a
DataGridViewback to the same text file from which it was imported, you can follow these steps. Below is an example to guide you through the process:Here's a sample implementation in C#:
Explanation:
Load Data from Text File to DataGridView
btnLoadFile_Clickmethod handles loading data from a text file into aDataTableand then binding thatDataTableto theDataGridView.Modify Data in DataGridView
DataGridView.Save Modified Data Back to Text File
btnSaveFile_Clickmethod converts theDataTableback to a string array with comma-separated values and writes this array back to the original file path usingFile.WriteAllLines.Conclusion:
This code provides a basic framework to import data from a text file into a
DataGridView, allow modifications, and then save the changes back to the same text file. Adapt this example as needed for your specific requirements.If this helps, please accept the answer to help others who might have the same question!