DataGridView records disappear after closing form

后端 未结 2 1773
我在风中等你
我在风中等你 2021-01-25 21:27

I have a datagridview that is not bound to a table in a database. The datagridview is being populated by the contents of a drop down list and a text box on a button click. I wan

2条回答
  •  时光说笑
    2021-01-25 22:12

    You can write your OWN class and save it as a setting-property.

    Class Settings:

    namespace MyNamespace
    {
        public class Settings
        {
            private ObservableCollection DataGridItemsProp;
            public ObservableCollection DataGridItems
            {
                 get { return DataGridItemsProp; }
                 set { DataGridItemsProp = value; }
            }
        }
    }
    

    Get and save your setting:

    //get settings
    var datagrid = Properties.Settings.Default.UserSettings;
    
    //save settings
    Properties.Settings.Default.UserSettings= datagrid;
    Properties.Settings.Default.Save();
    

提交回复
热议问题