This article shows how to save the user manipulation on the grid and restore those settings when the user runs the program.
When the user changes the DataGridView column order or changes the each column size or so on, we need to save these settings so we can restore the user DataGridView settings for the user to have the datagrid changes. To do this I'm going to create the XML file so I could store the settings.
I create 2 functions named ReadDataGridViewSetting() and WriteGrideViewSetting(), each one of them gets 2 parameters.
- writing function: I get 2 paramters, the first paramter is the datagrid that we want to save the settings for and the second is the name of the file that we want to save as XML like a.xml or setting.xml.
- reading: The Reading function takes 2 parameters, the first is the DataGridView that we want to restore its settings for and the second param is the name of the file that we saved as XML so then we read the paramter from the file then set each DataGridView column setting.
Then I initialize the grid and show it on the form.
I explained the rest of the function operations on the code.
Thank you for your time.