这两年一直在维护一套版本比较老的明基逐鹿MES系统,项目基于.Net Framework 3.5环境开发,这套软件使用了一套第三方控件库,Infragistics NetAdvantage Win Client:Windows Forms 2009.1,版本比较老旧,资料也不太好找。尽管如此,但是这套控件也确实还可以。
由于最近接到一个比较变态的需求,网上查资料再加上自己捣腾也总算实现出来。鉴于Infragistics资料不多,所以特地及记录下来,如果刚好有需要的小伙伴可以参考下,写的不好请见谅,如有疑问可私信。
需求下图是用户期望的操作界面。
其实就是在Grid内部根据确认内容列来决定显示何种控件类型。
checkbox和edit控件类型的容易实现而且资料比较好找,花了比较多时间的是下拉框记录绑定这一块。
实现出来的效果图如下
实现
UltraGrid 的InitializeLayout事件
private void ulDgvItem_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{
UltraGrid grid = sender as UltraGrid;
this._UltraWinGridHelper2 = new UltraWinGridHelper(this.ulDgvItem);
this._UltraWinGridHelper2.AddReadOnlyColumn("MAINID", "MAINID");
this._UltraWinGridHelper2.AddReadOnlyColumn("ID", "ID");
this._UltraWinGridHelper2.AddReadOnlyColumn("IPQA_ID", "IPQA_ID");
this._UltraWinGridHelper2.AddReadOnlyColumn("CONFIRMDEPT_ID", "CONFIRMDEPT_ID");
this._UltraWinGridHelper2.AddReadOnlyColumn("PROCESSNAME", "工序");
this._UltraWinGridHelper2.AddReadOnlyColumn("CHECKITEM", "检查内容");
this._UltraWinGridHelper2.AddReadOnlyColumn("CONFIRMCONTENT", "确认内容");
this._UltraWinGridHelper2.AddReadOnlyColumn("CONFIRMVALUE", "值");
this._UltraWinGridHelper2.AddReadOnlyColumn("REMARKS", "备注");
try
{
//自适应列宽
e.Layout.AutoFitColumns = false;
//e.Layout.Override.AllowColSizing = AllowColSizing.None;
e.Layout.Override.AllowDelete = Infragistics.Win.DefaultableBoolean.False;
e.Layout.Override.CellClickAction = CellClickAction.Edit;
// 自动判断是否显示前面的+、-号
e.Layout.Override.ExpansionIndicator = ShowExpansionIndicator.CheckOnDisplay;
// 设置Grid的Split窗口个数,建议设置为1--不允许Split
e.Layout.MaxColScrollRegions = 1;
e.Layout.MaxRowScrollRegions = 1;
e.Layout.Override.HeaderClickAction = Infragistics.Win.UltraWinGrid.HeaderClickAction.SortSingle;
e.Layout.Bands[0].Columns["MAINID"].Header.Caption = "MAINID";
e.Layout.Bands[0].Columns["MAINID"].Hidden = true;
e.Layout.Bands[0].Columns["ID"].Header.Caption = "ID";
e.Layout.Bands[0].Columns["ID"].Hidden = true;
e.Layout.Bands[0].Columns["IPQA_ID"].Header.Caption = "IPQA_ID";
e.Layout.Bands[0].Columns["IPQA_ID"].Hidden = true;
e.Layout.Bands[0].Columns["CONFIRMDEPT_ID"].Header.Caption = "IPQA_ID";
e.Layout.Bands[0].Columns["CONFIRMDEPT_ID"].Hidden = true;
e.Layout.Bands[0].Columns["PROCESSNAME"].Header.Caption = "工序";
e.Layout.Bands[0].Columns["PROCESSNAME"].Width = 50;
e.Layout.Bands[0].Columns["PROCESSNAME"].CellActivation = Infragistics.Win.UltraWinGrid.Activation.NoEdit;
e.Layout.Bands[0].Columns["CHECKITEM"].Header.Caption = "检查内容";
e.Layout.Bands[0].Columns["CHECKITEM"].Width = 450;
e.Layout.Bands[0].Columns["CHECKITEM"].CellActivation = Infragistics.Win.UltraWinGrid.Activation.NoEdit;
e.Layout.Bands[0].Columns["CONFIRMCONTENT"].Header.Caption = "确认内容";
e.Layout.Bands[0].Columns["CONFIRMCONTENT"].Width = 180;
e.Layout.Bands[0].Columns["CONFIRMCONTENT"].CellActivation = Infragistics.Win.UltraWinGrid.Activation.NoEdit;
e.Layout.Bands[0].Columns["CONFIRMVALUE"].Header.Caption = "值";
e.Layout.Bands[0].Columns["CONFIRMVALUE"].Width = 130;
e.Layout.Bands[0].Columns["REMARKS"].Header.Caption = "备注";
e.Layout.Bands[0].Columns["REMARKS"].Width = 220;
grid.DisplayLayout.Override.AllowRowFiltering = Infragistics.Win.DefaultableBoolean.True;
//过滤行
grid.DisplayLayout.Override.AllowRowFiltering = Infragistics.Win.DefaultableBoolean.True;
grid.DisplayLayout.Override.FilterUIType = FilterUIType.FilterRow;
grid.DisplayLayout.Override.SequenceFilterRow = 1;
//开启统计功能
grid.DisplayLayout.Bands[0].Override.AllowRowSummaries = AllowRowSummaries.True;
grid.DisplayLayout.Bands[0].Override.SummaryDisplayArea = SummaryDisplayAreas.GroupByRowsFooter | SummaryDisplayAreas.TopFixed;
}
catch
{
}
}
根据不同的检验项目设置不同的控件逻辑在数据绑定之后
private void BindItem(string _opCode,string _department,string _isnCode)
{
string strSql = string.Format(@"查询语句这里就不写出来了", _opCode.ToUpper(), _department, _isnCode);
var dt = this.DataProvider.ConditionQuery(new SQLCondition(strSql)).Tables[0];
this.ulDgvItem.DataSource = dt;
if (dt.Rows.Count > 0) {
SetDgvStyle(this.ulDgvItem);
}
}
private void SetDgvStyle(UltraGrid grid)
{
#region 历史程序列表
UltraDropDown UltraDropDown1 = new UltraDropDown(); //声明一个下拉框控件对象,这个对象要加载到UltraGrid中
UltraDropDown1.ValueMember = "FVALUE";
UltraDropDown1.DisplayMember = "FKEY";
string strSql = string.Format(@"select distinct CONFIRMVALUE FKEY,CONFIRMVALUE FVALUE from TBLIPQCCHECKITEMINFO
where ITEMCODE='{0}' and ISSOFTWARE=1 and ISDELETE=0 ", this.m_strItemCode);
DataTable dt = this.DataProvider.ConditionQuery(new SQLCondition(strSql)).Tables[0];
UltraDropDown1.DataSource = dt;
#endregion
foreach (var item in grid.Rows)
{
if (item.Cells["CONFIRMCONTENT"].Value.ToString() == "")
{
//确认内容没有内容的显示CheckBox
item.Cells["CONFIRMVALUE"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox;
if (item.Cells["CONFIRMVALUE"].Value.ToString() == "0" || item.Cells["CONFIRMVALUE"].Value.ToString().Trim() == "")
{
item.Cells["CONFIRMVALUE"].Value = false;
}
else
{
item.Cells["CONFIRMVALUE"].Value = true;
}
}
else if (item.Cells["CONFIRMCONTENT"].Value.ToString().Contains("程序"))
{
//包含了程序两个字的,显示下拉框
item.Cells["CONFIRMVALUE"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDown;
item.Cells["CONFIRMVALUE"].ValueList = UltraDropDown1;//除了设置单元格是DropDown类型,这一句很重要,否则是不会显示下拉选项的
}
else
{
//其他则正常显示输入框(默认就是文本框)
}
}
}