/// <summary>
        /// 控件创建事件
        /// </summary>
        protected override void OnCreateControl()
        {
            //判断配置文件是否存在
            if (!File.Exists(CP_ConfigPath))
            {
                return;
            }

            //读取配置
            Dictionary <string, bool> columns = DataGridViewOperate.LoadColumnVisibility(CP_ConfigPath, Name);

            //应用配置
            foreach (string key in columns.Keys)
            {
                if (Columns.Contains(key))
                {
                    Columns[key].Visible = columns[key];
                }
            }

            base.OnCreateControl();
        }
Beispiel #2
0
        private void FormDgvColumnVisibility_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!m_DataGridView.RowHeadersVisible && m_DataGridView.DisplayedColumnCount(true) == 0)
            {
                //判断配置文件是否存在
                if (!File.Exists(m_ConfigFile))
                {
                    for (int i = 0; i < m_DataGridView.Columns.Count; i++)
                    {
                        m_DataGridView.Columns[i].Visible = true;
                    }
                }
                else
                {
                    //读取配置
                    Dictionary <string, bool> columns = DataGridViewOperate.LoadColumnVisibility(m_ConfigFile, m_DataGridView.Name);

                    //应用配置
                    foreach (string key in columns.Keys)
                    {
                        if (m_DataGridView.Columns.Contains(key))
                        {
                            m_DataGridView.Columns[key].Visible = columns[key];
                        }
                    }
                }
            }

            //保存
            Dictionary <string, bool> visibility = new Dictionary <string, bool>();

            for (int i = 0; i < m_DataGridView.Columns.Count; i++)
            {
                visibility.Add(m_DataGridView.Columns[i].Name, m_DataGridView.Columns[i].Visible);
            }
            DataGridViewOperate.SaveColumnVisibility(m_ConfigFile, m_DataGridView.Name, visibility);
        }