场景:在Developer Express控件gridcontrol中的gridView中,当医生开的临时医嘱的医嘱类型为"中草药","计价总量"单元格不可以自由可输入,其余的医嘱类型,"计价总量"则可以自由输入。
由于查询资料,只有设置列的属性,没有设置某一个单元格的属性。参考链接:http://www.docin.com/p-278065085.html
解决办法:通过行焦点改变事件和列焦点改变事件进行控制单元格是否可用输入。
private void gridView_Lsyz_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) { if (this.CurrentOperationState == OperationState.emAddTempMedOrd || this.CurrentOperationState == OperationState.emEditTempMedOrd) { if (gridView_Lsyz.FocusedRowHandle >= 0) { //case 16954 object objyzlx = gridView_Lsyz.GetRowCellValue(gridView_Lsyz.FocusedRowHandle, colYzlx); if (objyzlx != null && objyzlx.ToString() != "") { if (objyzlx.ToString() == "自备药品") { if (ZBYIsFreeInput) { this.GridViewReadOnly(gridView_Lsyz, "DOSEUNIT", false); } } if (objyzlx.ToString() == "中草药") { //中草药计价总量不可输入Case#27998 this.GridViewReadOnly(gridView_Lsyz, "AMOUNT", true); } else { this.GridViewReadOnly(gridView_Lsyz, "DOSEUNIT", true); //非中草药计价总量可输入Case#27998 this.GridViewReadOnly(gridView_Lsyz, "AMOUNT", false); } } } } }
private void gridView_Lsyz_FocusedColumnChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedColumnChangedEventArgs e) { if (gridView_Lsyz.FocusedRowHandle >= 0) { DataRow currentRow = gridView_Lsyz.GetDataRow(gridView_Lsyz.FocusedRowHandle); if (currentRow["MEDORDTYPE"].ToString() != "中草药") { gridView_Lsyz.Columns["DOSECOUNT"].OptionsColumn.AllowFocus = false; this.GridViewReadOnly(gridView_Lsyz, "AMOUNT", false);//非中草药计价总量可输入Case#27998 } else { gridView_Lsyz.Columns["DOSECOUNT"].OptionsColumn.AllowFocus = true; this.GridViewReadOnly(gridView_Lsyz, "AMOUNT", true);//如果是中草药计价总量不可输入Case#27998 } } }
public void GridViewReadOnly(DevExpress.XtraGrid.Views.Grid.GridView gridView, string columnsName, bool readOnly) { if (!readOnly) { gridView.Columns[columnsName].OptionsColumn.ReadOnly = false; gridView.Columns[columnsName].OptionsColumn.AllowFocus = true; gridView.Columns[columnsName].OptionsColumn.AllowSize = true; } else { gridView.Columns[columnsName].OptionsColumn.ReadOnly = true; gridView.Columns[columnsName].OptionsColumn.AllowFocus = true; gridView.Columns[columnsName].OptionsColumn.AllowSize = true; } }