原因是因为C1ComboBox的绑定模式是双向绑定,而其中的Name属性又绑定到C1FlexGrid的ComBox列,采用的也是默认的双向绑定模式;这样当C1FlexGrid修改该列的值时,会直接修改C1ComboBox的数据源;
当下拉框修改选项后,按下ESC时,根据下拉框的按键事件判断:
- private void header_TextBoxKeyUp(object sender, KeyEventArgs e)
- {
- Key key = e.Key;
- if (key != Key.Return)
- {
- if (key != Key.Escape)
- {
- if (key != Key.F4)
- {
- return;
- }
- if (!KeyboardUtil.Alt)
- {
- this.IsDropDownOpen = !this.IsDropDownOpen;
- e.Handled = true;
- }
- }
- else if (this.IsDropDownOpen)
- {
- this.IsDropDownOpen = false;
- this._elementComboHeader.IsInEditMode = true;
- e.Handled = true;
- return;
- }
- }
- else
- {
- if (this._filterItem != null && this.SelectedItem == null && this.Condition == Condition.Contains && base.Items.Count > 0)
- {
- this.SelectedItem = base.Items[0];
- this.ClearFilterItemVisualState();
- }
- if (this.IsDropDownOpen)
- {
- this.IsDropDownOpen = false;
- }
- this._elementComboHeader.IsInEditMode = false;
- this._elementComboHeader.IsInEditMode = true;
- if (!this.isFound)
- {
- this._elementComboHeader._elementEditControl.Select(this._elementComboHeader._elementEditControl.Text.Length, 0);
- return;
- }
- }
- }
复制代码
其中并没有将C1ComboBox还原到之前选项操作,这时候下拉框还是最新的选项,而同时触发C1FlexGrid的ESC还原旧值事件,将该单元格的值设置成旧值,导致直接更新了C1ComboBox当前最新选项的Name,变成之前的旧值了。。。。
参考解决方案如下:
1、采用Alice方案,简单有效直接;
2、参考如下代码:
- private ComBoxModel _PreSelectedItem;
- void flx_PrepareCellForEdit(object sender, CellEditEventArgs e)
- {
- if (flx.Columns[e.Column].Header == "ComBox")
- {
- _PreSelectedItem = (flx.Rows[e.Row].DataItem as Person).ComBoxSelectItem;
- C1ComboBox cmb = (e.Editor as Border).Child as C1ComboBox;
- cmb.KeyDown -= cmb_KeyDown;
- cmb.KeyDown += cmb_KeyDown;
- }
- }
- void cmb_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.Key == Key.Escape)
- {
- C1ComboBox cmb = sender as C1ComboBox;
- cmb.SelectedItem = _PreSelectedItem;
- flx.FinishEditing(true);
- e.Handled = true;
- }
- }
复制代码 |