Esempio n. 1
0
        /// <summary>
        /// 保列宽
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btnSaveWidth_Click(object sender, EventArgs e)
        {
            #region 保存列宽
            if (ColumnWidthSave)
            {
                DataTable dt = new DataTable();
                for (int i = 0; i < this.Columns.Count; i++)
                {
                    dt.Columns.Add(this.Columns[i].Name);
                }
                //行数据
                object[] row = new object[this.Columns.Count];

                for (int k = 0; k < this.Columns.Count; k++)
                {
                    row[k] = this.Columns[k].Width.ToString();
                }
                dt.Rows.Add(row);

                string tagstr     = MyForm == null ? "" : MyForm.Tag == null ? "" : MyForm.Tag.ToString();
                string myformname = MyForm == null ? "" : MyForm.GetType().FullName;
                string nodename   = (myformname + tagstr + this.Name + "Width").Replace(".", "");

                //保存列宽
                DataGridViewConfig.WriteDGVConfig(UserName, nodename, dt);

                MessageBox.Show("保存成功!");
            }
            #endregion
        }
Esempio n. 2
0
        /// <summary>
        /// CheckedListBox_ItemCheck事件,保存设置是否显示列
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal void mCheckedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (ColumnVisibleEnableSave)
            {
                this.Columns[e.Index].Visible = (e.NewValue == CheckState.Checked);

                DataTable dt = new DataTable();
                for (int i = 0; i < this.Columns.Count; i++)
                {
                    dt.Columns.Add(this.Columns[i].Name);
                }
                //行数据
                object[] row = new object[this.Columns.Count];
                for (int k = 0; k < this.Columns.Count; k++)
                {
                    row[k] = this.Columns[k].Visible.ToString();
                }
                dt.Rows.Add(row);

                string tagstr     = MyForm == null ? "" : MyForm.Tag == null ? "" : MyForm.Tag.ToString();
                string myformname = MyForm == null ? "" : MyForm.GetType().FullName;
                string nodename   = (myformname + tagstr + this.Name).Replace(".", "");
                DataGridViewConfig.WriteDGVConfig(UserName, nodename, dt);
            }
        }
Esempio n. 3
0
 public void ShowColumnDisplayIndex()
 {
     #region 列显示顺序
     if (ColumnDisplayIndexSave)
     {
         if (dsindex == null || dsindex.Tables.Count <= 0 || dsindex.Tables[0].Rows.Count <= 0)
         {
             string tagstr     = MyForm == null ? "" : MyForm.Tag == null ? "" : MyForm.Tag.ToString();
             string myformname = MyForm == null ? "" : MyForm.GetType().FullName;
             string nodename   = (myformname + tagstr + this.Name + "Index").Replace(".", "");
             dsindex = DataGridViewConfig.ReadDGVConfig(UserName, nodename);
         }
         if (dsindex != null)
         {
             foreach (DataRow dr in dsindex.Tables[0].Rows)
             {
                 foreach (DataColumn col in dsindex.Tables[0].Columns)
                 {
                     if (this.Columns.Contains(col.ColumnName))
                     {
                         this.Columns[col.ColumnName].DisplayIndex = int.Parse(dr[col.ColumnName].ToString());
                     }
                 }
             }
         }
     }
     #endregion
 }
Esempio n. 4
0
        //保存列显示顺序
        void DataGridViewEx_ColumnDisplayIndexChanged(object sender, DataGridViewColumnEventArgs e)
        {
            if (ShowdgvTotalRow && this.dgvTotalRow != null)
            {
                for (int i = 0; i < this.ColumnCount; i++)
                {
                    this.dgvTotalRow.Columns[i].DisplayIndex = this.Columns[i].DisplayIndex;
                }
                this.SetScroll();
            }

            if (ColumnDisplayIndexSave)
            {
                DataTable dtindex = new DataTable();
                for (int i = 0; i < this.Columns.Count; i++)
                {
                    dtindex.Columns.Add(this.Columns[i].Name);
                }
                //行数据
                object[] rowindex = new object[this.Columns.Count];

                for (int k = 0; k < this.Columns.Count; k++)
                {
                    rowindex[k] = this.Columns[k].DisplayIndex;
                }
                dtindex.Rows.Add(rowindex);

                string tagstr        = MyForm == null ? "" : MyForm.Tag == null ? "" : MyForm.Tag.ToString();
                string myformname    = MyForm == null ? "" : MyForm.GetType().FullName;
                string nodenameindex = (myformname + tagstr + this.Name + "Index").Replace(".", "");

                //保存列位置
                DataGridViewConfig.WriteDGVConfig(UserName, nodenameindex, dtindex);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 列添加事件,设置列是否显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal void DataGridViewEx_ColumnAdded(object sender, DataGridViewColumnEventArgs e)
        {
            if (ColumnVisibleEnableSave)
            {
                if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0)
                {
                    string tagstr     = MyForm == null ? "" : MyForm.Tag == null ? "" : MyForm.Tag.ToString();
                    string myformname = MyForm == null ? "" : MyForm.GetType().FullName;
                    string nodename   = (myformname + tagstr + this.Name).Replace(".", "");
                    ds = DataGridViewConfig.ReadDGVConfig(UserName, nodename);
                }
                if (ds != null)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        foreach (DataColumn col in ds.Tables[0].Columns)
                        {
                            if (e.Column.Name == col.ColumnName)
                            {
                                e.Column.Visible = bool.Parse(dr[col.ColumnName].ToString());
                            }
                        }
                    }
                }
            }

            if (ColumnWidthSave)
            {
                if (dswidth == null || dswidth.Tables.Count <= 0 || dswidth.Tables[0].Rows.Count <= 0)
                {
                    string tagstr     = MyForm == null ? "" : MyForm.Tag == null ? "" : MyForm.Tag.ToString();
                    string myformname = MyForm == null ? "" : MyForm.GetType().FullName;
                    string nodename   = (myformname + tagstr + this.Name + "Width").Replace(".", "");
                    dswidth = DataGridViewConfig.ReadDGVConfig(UserName, nodename);
                }
                if (dswidth != null)
                {
                    this.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
                    foreach (DataRow dr in dswidth.Tables[0].Rows)
                    {
                        foreach (DataColumn col in dswidth.Tables[0].Columns)
                        {
                            if (e.Column.Name == col.ColumnName)
                            {
                                e.Column.Width = int.Parse(dr[col.ColumnName].ToString());
                            }
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        void DataGridViewEx_ColumnStateChanged(object sender, DataGridViewColumnStateChangedEventArgs e)
        {
            if (ShowdgvTotalRow && this.dgvTotalRow != null && dgvTotalRow.Columns.Count > 0)
            {
                for (int i = 0; i < this.ColumnCount; i++)
                {
                    this.dgvTotalRow.Columns[i].Visible = this.Columns[i].Visible;
                }
                this.SetScroll();
            }

            #region 设置列宽
            if (ColumnWidthSave)
            {
                if (dswidth == null || dswidth.Tables.Count <= 0 || dswidth.Tables[0].Rows.Count <= 0)
                {
                    string tagstr     = MyForm == null ? "" : MyForm.Tag == null ? "" : MyForm.Tag.ToString();
                    string myformname = MyForm == null ? "" : MyForm.GetType().FullName;
                    string nodename   = (myformname + tagstr + this.Name + "Width").Replace(".", "");
                    dswidth = DataGridViewConfig.ReadDGVConfig(UserName, nodename);
                }
                if (dswidth != null)
                {
                    this.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
                    foreach (DataRow dr in dswidth.Tables[0].Rows)
                    {
                        foreach (DataColumn col in dswidth.Tables[0].Columns)
                        {
                            if (e.Column.Name == col.ColumnName)
                            {
                                e.Column.Width = int.Parse(dr[col.ColumnName].ToString());
                            }
                        }
                    }
                }
            }
            #endregion
        }