UltraGrid 中嵌入类似CheckBoxList功能
来源:互联网 发布:数控车床圆弧编程 编辑:程序博客网 时间:2024/06/13 22:49
先说一下客户的需求,有点古怪
就是在某一列中,放一个类似的CheckBoxList的控件那样,可以多选的东东,选择几项保存的时候就插几条记录进数据库,其余的字段内容一样。
但是图上这个有CheckBoxList那行是Add上去的(Grid.DisplayLayout.Bands[0].AddNew();) 在点Save的时候是Insert 操作
原有的行则是从数据库出来的,在点击Save的时候则是Update操作,如下图,要求是下拉框了,因为Update的时候,只能保存成另外一个值,不可以让用户去多选
本来这样的形式在一样情况下可以正常出效果的(同一列不同单元格放不同的Editor),在Grid的InitializeRow事件,和在UltraGridRow row = Grid.DisplayLayout.Bands[0].AddNew();中对它们的Cell的EditorComponent进行设置是没有什么问题的,但是奇怪的是在当前这种情况下确出了问题,把上面保存操作的行上dropdownlist 绑定好,下面插入的新行绑定显示的checkboxlist多选的下拉框确出不来了!好像是互相排斥一样。在试了很多方法,又google了很多网页,包括官方社区以后。自己试出来要的图上的效果了。
说一下要点
1. 要绑定的那个CheckBoxList东东,不要动态创建,比如UltraComboEditor comboEditor = new UltraComboEditor ();
在设计界面拖一下UltraComboEditor 放在界面上Visable设成false
2.在绑定完Grid之前,直接设置列的编辑控件为UltraComboEditor
Grid.DisplayLayout.Bands[0].Columns["QualifierID"].EditorComponent = comboEditor;
3.在InitializeRow事件中再分别绑定
private void SetEditControlToRow(UltraGridRow row) { foreach (UltraGridCell gridCell in row.Cells) { switch (gridCell.Column.Key) { case "QualifierID": if (!string.IsNullOrEmpty(gridCell.Row.Cells["AllocationID"].Value + "")) { UltraCombo dropDown5 = new UltraCombo(); dropDown5.DataSource = _presenter.GetQualifierType(); dropDown5.DisplayMember = "QualifierType"; dropDown5.ValueMember = "QualifierID"; dropDown5.DisplayLayout.Bands[0].HeaderVisible = false; dropDown5.DisplayLayout.Bands[0].Columns[1].Hidden = true; gridCell.EditorComponent = dropDown5; dropDown5.RowSelected += new RowSelectedEventHandler(dropDown5_RowSelected); SetValueOnCell(gridCell, dropDown5); Grid.DisplayLayout.Bands[0].Columns["SubInventoryId"].Hidden = gridCell.Row.Cells["QualifierID"].Text.ToUpper() != "SUBINVENTORY"; } else { comboEditor.DataSource = _presenter.GetQualifierType(); comboEditor.DisplayMember = "QualifierType"; comboEditor.ValueMember = "QualifierID"; comboEditor.CheckedListSettings.CheckBoxAlignment = ContentAlignment.MiddleRight; comboEditor.CheckedListSettings.CheckBoxStyle = CheckStyle.CheckBox; comboEditor.CheckedListSettings.EditorValueSource = EditorWithComboValueSource.CheckedItems; comboEditor.CheckedListSettings.ListSeparator = ","; comboEditor.CheckedListSettings.ItemCheckArea = ItemCheckArea.Item; gridCell.EditorComponent = comboEditor; } break; } } }上面代码以行中有无主键ID为判断,有就是Update放上普通控件,无就是Insert设置成CheckBox下拉框。combEditor就是我拖到界面上的那个UltraComboEditor.
重点解释一下下面这几行代码
comboEditor.CheckedListSettings.CheckBoxAlignment = ContentAlignment.MiddleRight; comboEditor.CheckedListSettings.CheckBoxStyle = CheckStyle.CheckBox; comboEditor.CheckedListSettings.EditorValueSource = EditorWithComboValueSource.CheckedItems; comboEditor.CheckedListSettings.ListSeparator = ","; comboEditor.CheckedListSettings.ItemCheckArea = ItemCheckArea.Item;comboEditor.CheckedListSettings.CheckBoxAlignment = ContentAlignment.MiddleRight;checkbox对齐方式comboEditor.CheckedListSettings.CheckBoxStyle = CheckStyle.CheckBox;显示为CheckBox,也可以设置成三态TriState,None等,这里需要多选,所以就CheckBoxcomboEditor.CheckedListSettings.EditorValueSource = EditorWithComboValueSource.CheckedItems;设置该Editor为选中的Item值,也可以设置为SelectedItem,这样只点击那一项,不用打勾也行comboEditor.CheckedListSettings.ItemCheckArea = ItemCheckArea.Item;设置点击点为选中的区域,Item是点击那一项,Checkbox为为CheckBox打勾才算选中
- UltraGrid 中嵌入类似CheckBoxList功能
- UltraGrid 中嵌入类似CheckBoxList功能
- WinForm中类似WebForm中的CheckBoxList控件
- asp.net中实现CheckBoxList单选功能
- XCode中类似reveal功能
- [WinForm每日一帖] UltraGrid中增删改功能推荐做法
- UltraGrid
- UltraGrid
- checkboxlist 下拉框多选功能
- 关于hibernate中实体类为什么尽量序列化和类似<s:checkboxlist/>标签
- 在应用程序中嵌入数据库功能
- 在QT4中使用类似QVBox类似功能
- 在QT4中使用类似QVBox类似功能
- 在QT4中使用类似QVBox类似功能
- Opencv 中类似matlab的subplot功能
- C++中类似C# region的功能
- jsp中类似gridview的功能
- MySql实现类似Oracle中Row_number功能
- Spring DM Server的部署与应用
- c# 对文件的操作
- 浮点数的内存结构
- 解释神马的都是浮云…
- 设备枚举
- UltraGrid 中嵌入类似CheckBoxList功能
- 史上最具有内涵的程序猿面试题目
- 进入当前文件直接拉分支
- lcov检查覆盖率命令
- MySQL中修改密码及访问限制设置详解
- 用VC进行COM编程的初级教程(转)
- php - zoj 1295
- Struts1中action线程安全问题
- NHibernate进行 Text字段映射