private static void ReloadNvFromGridCell(EventProcessInfo eventProcessInfo, IDisplayManager dm, Xceed.Grid.Cell cell, string changedDataControlName) { string[] columns = eventProcessInfo.ExecuteParam.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string s in columns) { Xceed.Grid.Cell iCell = cell.ParentRow.Cells[s]; if (iCell == null) { continue; //throw new ArgumentException("there is no column with name " + s + "!"); } GridColumnInfo iInfo = iCell.ParentColumn.Tag as GridColumnInfo; switch (iInfo.CellEditorManager) { case "Combo": case "MultiCombo": case "FreeCombo": { NameValueMapping nv = NameValueMappingCollection.Instance[iInfo.CellEditorManagerParam]; List <string> ls = new List <string>(); foreach (KeyValuePair <string, object> kvp in nv.Params) { ls.Add(kvp.Key.Substring(1)); } if (!ls.Contains(changedDataControlName)) { continue; } iCell.Value = null; foreach (string key in ls) { object o = GetDataCellValue(key, iCell).Item2; nv.Params["@" + key] = o == null ? System.DBNull.Value : o; } NameValueMappingCollection.Instance.Reload(dm.Name, iInfo.CellEditorManagerParam); // when in grid, we can't use comboBox's DataTableChanged because combobox only created when in edit System.Data.DataView dv = NameValueMappingCollection.Instance.GetDataSource(dm.Name, iInfo.CellEditorManagerParam, iInfo.CellEditorManagerParamFilter); if (dv.Count == 1) { object toValue = dv[0][NameValueMappingCollection.Instance[iInfo.CellEditorManagerParam].ValueMember]; if (!Feng.Utils.ReflectionHelper.ObjectEquals(iCell.Value, toValue)) { dm.OnSelectedDataValueChanged(new SelectedDataValueChangedEventArgs(s, iCell)); } iCell.Value = toValue; } iCell.ReadOnly = (dv.Count == 0); nv.ResetParams(); } break; case "ObjectPicker": { // Todo: if (!ls.Contains(changedDataControlName)) iCell.Value = null; Feng.Windows.Forms.MyObjectPicker op = (iCell.CellEditorManager as Feng.Grid.Editors.MyObjectPickerEditor).TemplateControl; string exp = (string)ParamCreatorHelper.TryGetParam(iInfo.CellEditorManagerParamFilter); exp = EntityHelper.ReplaceEntity(exp, new EntityHelper.GetReplaceValue(delegate(string paramName) { return(GetDataCellValue(paramName, iCell).Item2); })); op.DropDownControl.DisplayManager.SearchManager.LoadData(SearchExpression.Parse(exp), null); } break; } } }
private static void ReloadNvFromGridCell(EventProcessInfo eventProcessInfo, IDisplayManager dm, Xceed.Grid.Cell cell, string changedDataControlName) { string[] columns = eventProcessInfo.ExecuteParam.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string s in columns) { Xceed.Grid.Cell iCell = cell.ParentRow.Cells[s]; if (iCell == null) { continue; //throw new ArgumentException("there is no column with name " + s + "!"); } GridColumnInfo iInfo = iCell.ParentColumn.Tag as GridColumnInfo; switch (iInfo.CellEditorManager) { case "Combo": case "MultiCombo": case "FreeCombo": { NameValueMapping nv = NameValueMappingCollection.Instance[iInfo.CellEditorManagerParam]; List<string> ls = new List<string>(); foreach (KeyValuePair<string, object> kvp in nv.Params) { ls.Add(kvp.Key.Substring(1)); } if (!ls.Contains(changedDataControlName)) continue; iCell.Value = null; foreach (string key in ls) { object o = GetDataCellValue(key, iCell).Item2; nv.Params["@" + key] = o == null ? System.DBNull.Value : o; } NameValueMappingCollection.Instance.Reload(dm.Name, iInfo.CellEditorManagerParam); // when in grid, we can't use comboBox's DataTableChanged because combobox only created when in edit System.Data.DataView dv = NameValueMappingCollection.Instance.GetDataSource(dm.Name, iInfo.CellEditorManagerParam, iInfo.CellEditorManagerParamFilter); if (dv.Count == 1) { object toValue = dv[0][NameValueMappingCollection.Instance[iInfo.CellEditorManagerParam].ValueMember]; if (!Feng.Utils.ReflectionHelper.ObjectEquals(iCell.Value, toValue)) { dm.OnSelectedDataValueChanged(new SelectedDataValueChangedEventArgs(s, iCell)); } iCell.Value = toValue; } iCell.ReadOnly = (dv.Count == 0); nv.ResetParams(); } break; case "ObjectPicker": { // Todo: if (!ls.Contains(changedDataControlName)) iCell.Value = null; Feng.Windows.Forms.MyObjectPicker op = (iCell.CellEditorManager as Feng.Grid.Editors.MyObjectPickerEditor).TemplateControl; string exp = (string)ParamCreatorHelper.TryGetParam(iInfo.CellEditorManagerParamFilter); exp = EntityHelper.ReplaceEntity(exp, new EntityHelper.GetReplaceValue(delegate(string paramName) { return GetDataCellValue(paramName, iCell).Item2; })); op.DropDownControl.DisplayManager.SearchManager.LoadData(SearchExpression.Parse(exp), null); } break; } } }