GridControl中属性

1.只读的单元格为灰色

        //只读单元格为灰色
        private void invDataGridView_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            //已显示的只读列,设置背景为灰色
            if (e.Column.Visible != false && e.Column.ReadOnly == true)
            {
                e.Appearance.BackColor = Color.Gainsboro;
            }
        }

2.增加筛选框

如下:

 

 

        private void invDataGridView_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        {
            if (e.RowHandle == GridControl.AutoFilterRowHandle)
            {
                e.Info.DisplayText = "筛选";   //筛选行加行标题
                e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;//居中
            }
            PublicMethod.SetGridViewRowNo(e);
        }

3.Changing事件

        private void gridviewtoupiinfo_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e != null && e.Value != null)
            {
                string ColName = e.Column.Name;//列名
                string Value = e.Value.ToString();//列当前值
                int RowIndex = e.RowHandle;//获取当前行标

                if (ColName == "Colmustqty" || ColName == "Colmustnum" )
                {
                    if (Value != "")
                    {
                        if ((!Regex.IsMatch(Value, "^[0-9]+(\\.[0-9]*)?$")))
                        {
                            MessageBox.Show("请输入正确数值!", "提示");
                            invDataGridView.CloseEditor();
                            return;
                        }
                        if (Value.Replace("-", "").Substring(0, Value.Replace("-", "").IndexOf(".") == -1 ? Value.Replace("-", "").Length : Value.Replace("-", "").IndexOf(".")).Length > 9)
                        {
                            MessageBox.Show("输入数值位数过大,请重新输入!", "提示");
                            invDataGridView.CloseEditor();
                            return;
                        }
                    }
                }
            }
        }

 自定义合计:

  colgreprice.SummaryItem.SetSummary(DevExpress.Data.SummaryItemType.Custom, Math.Round(Convert.ToDecimal(gridViewmain.Columns["greamount"].SummaryItem.SummaryValue)
                    / Convert.ToDecimal(gridViewmain.Columns["qty"].SummaryItem.SummaryValue), 2).ToString());//坯布单价计算

 

posted on 2021-01-21 08:54  RookieBoy666  阅读(138)  评论(0编辑  收藏  举报