找回密码
 立即注册

QQ登录

只需一步,快速开始

q406157290

高级会员

124

主题

531

帖子

1359

积分

高级会员

积分
1359

活字格认证

q406157290
高级会员   /  发表于:2016-1-20 16:35  /   查看:9538  /  回复:9




代码:(代码画面是ComBoxWindow, 具体处理在ComBoxWindow.cs中)

如图所示的操作选择发生变化后,按ESC后,目的是还原到选择前的值,可是现在却把ComBox的数据源里的值改变了,如何修正这种情况

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

9 个回复

倒序浏览
Alice
社区贡献组   /  发表于:2016-1-20 17:30:00
沙发
回复 1楼q406157290的帖子

谢谢您提供的Demo以及详细的步骤。
您的问题我们收到了,测试后给您反馈。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2016-1-21 11:16:00
板凳
回复 1楼q406157290的帖子

问题已经重现。
我们需要调查您的程序是哪里出了问题。有结果会在第一时间反馈给您。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
q406157290
高级会员   /  发表于:2016-1-21 13:34:00
地板
回复 3楼Alice的帖子

好的  谢谢您  我发现的是按ESC只把SelectItem里的Name修改成原始数据,但是Id没有变更,所以才导致这种情况
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2016-1-21 17:09:00
5#
回复 4楼q406157290的帖子

好的,谢谢您的反馈。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2016-1-22 09:47:00
6#
回复 1楼q406157290的帖子

经过调查,建议您当取消改变的时候,重新计算ComboBox list。
以下是建议的代码:
  1. void populateList()
  2.         {
  3.             //ComBox数据源
  4.             DataListVM.ComBoxList.Add(new ComBoxModel() { Id = "1", Name = "111" });
  5.             DataListVM.ComBoxList.Add(new ComBoxModel() { Id = "2", Name = "222" });
  6.             DataListVM.ComBoxList.Add(new ComBoxModel() { Id = "3", Name = "333" });
  7.         }



  8.         private void C1FlexGrid_CellEditEnding(object sender, C1.WPF.FlexGrid.CellEditEventArgs e)
  9.         {
  10.             C1FlexGrid grid = sender as C1FlexGrid;
  11.             if (e.CancelEdits)
  12.             {

  13.                 //Person p = grid.Rows[e.Row].DataItem as Person;
  14.                 //p.ComBoxSelectItem = DataListVM.ComBoxList[0];
  15.                 DataListVM.ComBoxList.Clear();
  16.                 populateList();
  17.             }

  18.         }
复制代码

请参考附件的Demo。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
KNight
中级会员   /  发表于:2016-1-22 11:43:00
7#
原因是因为C1ComboBox的绑定模式是双向绑定,而其中的Name属性又绑定到C1FlexGrid的ComBox列,采用的也是默认的双向绑定模式;这样当C1FlexGrid修改该列的值时,会直接修改C1ComboBox的数据源;

当下拉框修改选项后,按下ESC时,根据下拉框的按键事件判断:
  1. private void header_TextBoxKeyUp(object sender, KeyEventArgs e)
  2. {
  3.         Key key = e.Key;
  4.         if (key != Key.Return)
  5.         {
  6.                 if (key != Key.Escape)
  7.                 {
  8.                         if (key != Key.F4)
  9.                         {
  10.                                 return;
  11.                         }
  12.                         if (!KeyboardUtil.Alt)
  13.                         {
  14.                                 this.IsDropDownOpen = !this.IsDropDownOpen;
  15.                                 e.Handled = true;
  16.                         }
  17.                 }
  18.                 else if (this.IsDropDownOpen)
  19.                 {
  20.                         this.IsDropDownOpen = false;
  21.                         this._elementComboHeader.IsInEditMode = true;
  22.                         e.Handled = true;
  23.                         return;
  24.                 }
  25.         }
  26.         else
  27.         {
  28.                 if (this._filterItem != null && this.SelectedItem == null && this.Condition == Condition.Contains && base.Items.Count > 0)
  29.                 {
  30.                         this.SelectedItem = base.Items[0];
  31.                         this.ClearFilterItemVisualState();
  32.                 }
  33.                 if (this.IsDropDownOpen)
  34.                 {
  35.                         this.IsDropDownOpen = false;
  36.                 }
  37.                 this._elementComboHeader.IsInEditMode = false;
  38.                 this._elementComboHeader.IsInEditMode = true;
  39.                 if (!this.isFound)
  40.                 {
  41.                         this._elementComboHeader._elementEditControl.Select(this._elementComboHeader._elementEditControl.Text.Length, 0);
  42.                         return;
  43.                 }
  44.         }
  45. }
复制代码

其中并没有将C1ComboBox还原到之前选项操作,这时候下拉框还是最新的选项,而同时触发C1FlexGrid的ESC还原旧值事件,将该单元格的值设置成旧值,导致直接更新了C1ComboBox当前最新选项的Name,变成之前的旧值了。。。。

参考解决方案如下:
1、采用Alice方案,简单有效直接;
2、参考如下代码:
  1. private ComBoxModel _PreSelectedItem;
  2. void flx_PrepareCellForEdit(object sender, CellEditEventArgs e)
  3. {
  4.         if (flx.Columns[e.Column].Header == "ComBox")
  5.         {
  6.                 _PreSelectedItem = (flx.Rows[e.Row].DataItem as Person).ComBoxSelectItem;

  7.                 C1ComboBox cmb = (e.Editor as Border).Child as C1ComboBox;
  8.                 cmb.KeyDown -= cmb_KeyDown;
  9.                 cmb.KeyDown += cmb_KeyDown;
  10.         }
  11. }

  12. void cmb_KeyDown(object sender, KeyEventArgs e)
  13. {
  14.         if (e.Key == Key.Escape)
  15.         {
  16.                 C1ComboBox cmb = sender as C1ComboBox;
  17.                 cmb.SelectedItem = _PreSelectedItem;
  18.                 flx.FinishEditing(true);
  19.                 e.Handled = true;
  20.         }
  21. }
复制代码
回复 使用道具 举报
q406157290
高级会员   /  发表于:2016-1-22 13:51:00
8#
回复 7楼KNight的帖子

非常感谢大家给我的建议,在提问前我有自己的方法,只不过不满意,所以问下,我的方法是如下,在按Esc的时候把ComBox里的SelectedValue 设置会原始数据


  1. public void c1DataGrid1_CellEditEnding(object sender, CellEditEventArgs e)
  2.         {
  3.             C1FlexGrid flexGrid = sender as C1FlexGrid;
  4.             //原数据
  5.             Object PreSelectedValue = 111;
  6.             Border bdr = flexGrid.ActiveEditor as Border;
  7.             if (bdr != null)
  8.             {
  9.                 C1.WPF.C1ComboBox comboBox = bdr.Child as C1.WPF.C1ComboBox;

  10.                 if (comboBox != null)
  11.                 {
  12.                     if (e.CancelEdits)
  13.                     {
  14.                         comboBox.SelectedValue = PreSelectedValue;
  15.                     }
  16.                 }
  17.             }

  18.         }
复制代码

评分

参与人数 1金币 +999 收起 理由
Alice + 999 奖励金币

查看全部评分

回复 使用道具 举报
q406157290
高级会员   /  发表于:2016-1-22 13:52:00
9#
回复 6楼Alice的帖子

谢谢您的建议
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2016-1-22 17:20:00
10#
回复 9楼q406157290的帖子

不用客气
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部