예제 #1
0
        /// <summary>
        /// 初始化控件
        /// </summary>
        /// <param name="form"></param>
        /// <param name="dgv"></param>
        /// <param name="json"></param>
        /// <param name="usingCheck">是否使用复选列</param>
        /// <param name="usingNo">是否使用编号</param>
        /// <returns></returns>
        public bool Init(DataGridView dgv, string json, bool usingCheck = false, bool usingNo = false)
        {
            if (!string.IsNullOrWhiteSpace(json))
            {
                clsList = HiCSUtil.Json.Json2Obj <List <DGVColumnInfo> >(json);
            }
            else
            {
                clsList = new List <DGVColumnInfo>();
            }

            int index = 0;

            foreach (var it in clsList)
            {
                columns[it.ColumnID] = it;
                it.DipplayIndex      = index;
                index++;
            }
            bool result = Init(dgv, usingCheck);

            if (usingCheck || ColumnHasChk())                // 用户自己添加的列不需要自动添加相关事件
            {
                dgv.CellClick += DGViewEvent.CheckCellClick; // 设置多选控件事件
            }

            if (usingNo)
            {
                DGViewUtil.SetRowNo(dgv);
            }
            return(true);
        }
예제 #2
0
        private void SetRowColor_Evt(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            DataGridView dgv = sender as DataGridView;

            if (dgv == null)
            {
                return;
            }
            DataGridViewRow row = dgv.Rows[e.RowIndex];

            if (DGViewUtil.IsRowSelected(dgv, CheckBoxIndex, e.RowIndex))
            {
                SetColor(row.DefaultCellStyle, selColor);
            }
            else
            {
                if (e.RowIndex % 2 == 0)
                {
                    SetColor(row.DefaultCellStyle, defColor);
                }
                else
                {
                    SetColor(row.DefaultCellStyle, altColor);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 初始化控件
        /// </summary>
        /// <param name="form"></param>
        /// <param name="dgv"></param>
        /// <param name="cls"></param>
        /// <returns></returns>
        private bool Init(DataGridView dgv, bool isUsingCheck)
        {
            if (dgv == null)
            {
                return(false);
            }

            myDGV = dgv;
            dgv.AutoGenerateColumns = false;
            dgv.AutoSizeRowsMode    = DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders;
            dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            InitExistColumns8Tag(dgv);                                // 对已存在的列进行处理

            if (CheckBoxIndex < 0 && isUsingCheck && !ColumnHasChk()) // 自动创建多选列
            {
                checkColumn = DGViewUtil.CreateCheckBoxColumn(20, true);
                myDGV.Columns.Add(checkColumn);
            }


            DataGridViewCheckBoxColumn chk = DGVColumnInfo.CreateAndInitControls(clsList, dgv); // 创建不存在的列并设置相关信息

            if (chk != null)                                                                    // 自动创建多选列
            {
                checkColumn = chk;
            }

            OnResize();     // 设置列宽
            return(true);
        }
예제 #4
0
 /// <summary>
 /// 常见列
 /// </summary>
 /// <param name="info"></param>
 /// <returns></returns>
 private static DataGridViewColumn CreateControl(DGVColumnInfo info)
 {
     if (info.Type.ToLower().Equals("chk"))
     {
         return(DGViewUtil.CreateCheckBoxColumn());
     }
     else if (info.Type.ToLower().Equals("chk_head"))
     {
         return(DGViewUtil.CreateCheckBoxColumn(20, true));
     }
     else
     {
         DataGridViewColumn ex = new DataGridViewTextBoxColumn();
         ex.Tag = info.ColumnID;
         if (info.IsShow == 0)
         {
             ex.Visible = false;
         }
         ex.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
         return(ex);
     }
 }
예제 #5
0
 /// <summary>
 /// 取得视图某行某列的值
 /// </summary>
 /// <param name="rowIndex"></param>
 /// <param name="cellIndex"></param>
 /// <returns></returns>
 public string GetCellValue(int rowIndex, int cellIndex)
 {
     return(DGViewUtil.GetCellValue(myDGV, rowIndex, cellIndex));
 }
예제 #6
0
 /// <summary>
 /// 某行是否已选择
 /// </summary>
 /// <param name="rowIndex"></param>
 /// <returns></returns>
 public bool IsRowSelected(int rowIndex)
 {
     return(DGViewUtil.IsRowSelected(myDGV, CheckBoxIndex, rowIndex));
 }
예제 #7
0
 /// <summary>
 /// 取得视图某行某列的值
 /// </summary>
 /// <param name="rowIndex"></param>
 /// <param name="columnName"></param>
 /// <returns></returns>
 public string GetCellValue(int rowIndex, string columnName)
 {
     return(DGViewUtil.GetCellValue(myDGV, rowIndex, columnName));
 }