我在使用Dev的xtraGrid控件时,需要添加某个值字段的关联信息,比如物料的ID信息为保存值,但是名称、规格为关联显示字段,不需要保存;因此设计xtraGrid表格时,ID字段为绑定数据库字段;名称、规格型号为非绑定字段。但是,在对CustomUnboundColumnData事件做断点监控的时候发现,程序一直在执行CustomUnboundColumnData这个事件(用SQL的事件工具进行跟踪,发现一直在执行查询)。
代码如下:
private void EntryGrid_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
int rowID = e.ListSourceRowIndex;
if (EntryGrid.GetRowCellValue(rowID, EntryGrid.Columns["FItemID"]).ToString().Trim() == "")
{
return;
}
else
{
DataTable _Tbl = new DataTable();
int ItemID = int.Parse(EntryGrid.GetRowCellValue(rowID, EntryGrid.Columns["FItemID"]).ToString());
string _sql = string.Format("Select A.FNumber,A.FName,A.FModel,B.FName AS FUnit,A.FProductUnitID AS FUnitID From T_ICItem A Inner Join t_MeasureUnit B on A.FProductUnitID=B.FMeasureUnitID Where A.FItemID={0}", ItemID);
_Tbl = db.GetData(_sql);
switch (e.Column.FieldName)
{
case "FName":
if (e.IsGetData == true) e.Value = _Tbl.Rows[0]["FName"].ToString();
break;
case "FModel":
if (e.IsGetData == true) e.Value = _Tbl.Rows[0]["FModel"].ToString();
break;
case "FUnit":
if (e.IsGetData == true)
{
e.Value = _Tbl.Rows[0]["FUnit"].ToString();
DataRow CurRow = Entry_tbl.Rows[rowID];
CurRow["FUnitID"] = _Tbl.Rows[0]["FUnitID"];
}
break;
default:
break;
}
}
}