Saving the layout of the data grid view (width, order) in Visual Studio

I have some Grid Views data, and I want the user to be able to save the changes that he makes to them. The data does not change, only the layout changes, such as the width, height, order of the columns and, possibly, their visibility. I don't care if it will be automatic or at the touch of a button ...

Edit: I found a way to do this using settings. I added a settings file, but I have no idea how I should add the column order or column size in these settings

+3
source share
3 answers

, , cookie/database , .

0

/ , , db, registry, xml, config ..... .

0

, , DataGridGiew. , , , .

, , :

DataGridView.SortedColumn , . DataGridView.SortOrder ( )

DataGridView.Columns.

, , (, " " ) , . , - . , - , , - . , (, "" "" ). , :

// e.g. you defined an integer user setting at design time called ColA_Width, to
// hold the value of the width of "ColA" in your DataGridView.

// Use this code to save the value (either in a specific event handler, or a 
// global "save settings" routine).
Properties.Settings.Default.ColA_Width = MyDataGridViewInstance.Columns["ColA"].Width;
Properties.SEttings.Default.Save();

// Then you'd reverse the assignments when the app next loads so that the saved 
// settings are "remembered" between user sessions.
MyDataGridViewInstance.Columns["ColA"].Width = Properties.Settings.Default.ColA_Width;

The only caveats I can recall are that some of the values ​​of the DataGridView properties are not just saved as strings (remember that your user preferences are eventually saved as XML), but it really depends on what settings you save.

0
source

Source: https://habr.com/ru/post/1715197/


All Articles