设置列的只读属性

private void barButtonItem查询_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            barStaticItem3.Caption = "正在执行:查询";

            DataSet ds = new DataSet();
            string strwhere = " where 1=1";
            if (barCheckItem1.Checked)
            {
                strwhere += " and  变更日期 <'" + ((DateTime)barEditItem2.EditValue).Date.AddDays(1) + "'  and 截止日期> '" + ((DateTime)barEditItem1.EditValue).Date + "' ";
            }
            else
            {
                strwhere += " and  变更日期 <'" + ((DateTime)barEditItem2.EditValue).Date.AddDays(1) + "'  and 截止日期> '" + ((DateTime)barEditItem2.EditValue).Date + "' ";
            }
            if (DbHelperSQL2.Authorized("部门用户"))
            {
                strwhere += " and 部门编号='" + MainForm.UserDepartmentid + "' ";
            }

            //ds = DbHelperSQL2.Query("select * from employeeR " + strwhere);// where 收入日期<= Convert(nvarchar(7),'" + ((DateTime)barEditItem2.EditValue).ToString("yyyy-MM") + "',120)  and 日期>= Convert(nvarchar(7),'" + ((DateTime)barEditItem1.EditValue).ToString("yyyy-MM") + "',120)");
            bandedGridView1.Columns.Clear();
            //gridControl1.DataSource = null;
            //gridControl1.DataSource = ds.Tables[0];

            string SQLString = "select * from employeeR " + strwhere;
            using (SqlConnection connection = new SqlConnection(Conn.sqlstr))
            {
                try
                {
                    connection.Open();
                    SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);
                    command.Fill(ds, "ds");
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    throw new Exception(ex.Message);
                }
            }
            gridControl1.DataSource = ds.Tables[0];
            gridfile = System.Windows.Forms.Application.StartupPath + "//" + MainForm.UserName + "//" + this.Name + "grid.xml";
            if (comboBoxEdit1.EditValue != null)
            {
                gridControl1.LookAndFeel.SkinName = comboBoxEdit1.EditValue.ToString();

            }
            if (cbeStyles.EditValue != null)
            {
                xapp.LoadScheme(cbeStyles.EditValue.ToString(), gridControl1.DefaultView); //gridControl1.MainView;
            }

            if (System.IO.File.Exists(Appearancefile))
            {
                bandedGridView1.Appearance.RestoreLayoutFromXml(Appearancefile);
            }
            if (System.IO.File.Exists(gridfile))
            {
                bandedGridView1.RestoreLayoutFromXml(gridfile);
            }
            string[] strs ={ "变更日期", "截止日期", "录入时间" };
            foreach (string var in strs)
            {
                if (bandedGridView1.Columns[var].Visible)
                {
                    bandedGridView1.Columns[var].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;
                    bandedGridView1.Columns[var].DisplayFormat.FormatString = "G";
                }
            }
            bandedGridView1.Columns["ID"].OptionsColumn.ReadOnly = true;
            bandedGridView1.Columns["ID"].OptionsColumn.AllowEdit = false;
            bandedGridView1.Columns["录入时间"].OptionsColumn.ReadOnly = true;//只读,不可选择,不可修改
            bandedGridView1.Columns["录入时间"].OptionsColumn.AllowEdit = false;//可选择,不可修改
            bandedGridView1.Columns["录入人员"].OptionsColumn.ReadOnly = true;
            bandedGridView1.Columns["录入人员"].OptionsColumn.AllowEdit = false;
            bandedGridView1.Columns["录入部门"].OptionsColumn.ReadOnly = true;
            bandedGridView1.Columns["录入部门"].OptionsColumn.AllowEdit = false;

            barStaticItem2.Caption = "共计:" + bandedGridView1.RowCount + " 条记录";
            barStaticItem1.Caption = "没有选中任何记录";
            barStaticItem3.Caption = "查询完毕";
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值