利用gridControl的layoutView来编辑记录和修改
将gridControl默认下的mainView改为layoutView后,按照自己的需求去排版字段,达到最佳效果.为防止有人误点击保存按钮,默认情况下,我将所有字段都设置为不可编辑状态,即autoEdit = false,设计界面如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 private void simpleButton1_Click(object sender, EventArgs e)
2 {
3 if (!checkFun(sender))
4 {
5 XtraMessageBox.Show("您没有此操作权限.", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
6 return;
7 }
8 foreach (DevExpress.XtraGrid.Columns.GridColumn item in layoutView1.Columns)
9 {
10 item.OptionsColumn.AllowEdit = !Convert.ToBoolean(item.Tag);
11 }
12 XtraMessageBox.Show("直接点击要编辑的字段,编辑完成后点击保存即可生效!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
13 simpleButton2.Enabled = true;
14 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 private void simpleButton2_Click(object sender, EventArgs e)
2 {
3 if (!checkFun(sender))
4 {
5 XtraMessageBox.Show("您没有此操作权限.", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
6 return;
7 }
8 DataSet ds = moreDate.domainModify.DataSet;
9 if (ds.HasChanges())
10 {
11 DataSet dsModify = ds.GetChanges();
12 if (dsModify != null)
13 {
14 this.domainModifyTableAdapter.Update(moreDate.domainModify);
15 ds.AcceptChanges();
16
17 XtraMessageBox.Show("保存成功.", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
18 }
19 }
20 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 private void simpleButton3_Click(object sender, EventArgs e)
2 {
3 if (!checkFun(sender))
4 {
5 XtraMessageBox.Show("您没有此操作权限.", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
6 return;
7 }
8 layoutView1.AddNewRow();
9 simpleButton2.Enabled = true;
10 XtraMessageBox.Show("请在此空白卡片上将要录入的内容填完全,然后点击保存内容按钮使其生效!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
11 foreach (DevExpress.XtraGrid.Columns.GridColumn item in layoutView1.Columns)
12 {
13 item.OptionsColumn.AllowEdit = !Convert.ToBoolean(item.Tag);
14 }
15 }