private void LoadDataObject() { ITreeListViewHoster treeListHoster = _TreeListHoster; IList lstDatas = null; try { int id = (int)_SortingNode.GetValue(_TreeListHoster.TreeViewCfg.KeyFieldName); MB.Util.Model.QueryParameterInfo[] queryParams = new Util.Model.QueryParameterInfo[1]; queryParams[0] = new Util.Model.QueryParameterInfo(_TreeListHoster.TreeViewCfg.ParentFieldName, id, Util.DataFilterConditions.Equal); lstDatas = _ClientRuleObject.GetObjects((int)_ClientRuleObject.MainDataTypeInDoc, queryParams); } catch (Exception ex) { throw MB.Util.APPExceptionHandlerHelper.PromoteException(ex, "DefaultTreeListViewForm.GetObjects 出错!"); } if (_BindingSource == null) { IBindingList bl = _ClientRuleObject.CreateMainBindList(lstDatas); _BindingSource = new MB.WinBase.Binding.BindingSourceEx(); _BindingSource.DataSource = bl; treeListHoster.CreateTreeListViewDataBinding(trvLstMain, _BindingSource); if (trvLstMain.Nodes.Count > 0) { trvLstMain.Nodes[0].Expanded = true; trvLstMain.FocusedNode = trvLstMain.Nodes[0]; } } else { treeListHoster.RefreshTreeListData(trvLstMain, lstDatas); } }
protected override void LoadObjectData(MB.Util.Model.QueryParameterInfo[] queryParams) { if (_ClientRuleObject == null) { throw new MB.Util.APPException("在加载浏览窗口<DefaultViewForm>时 需要配置对应的ClientRule 类!"); } if (_ClientRuleObject.ClientLayoutAttribute == null) { throw new MB.Util.APPException(string.Format("对于客户段逻辑类 {0} ,需要配置 RuleClientLayoutAttribute.", _ClientRuleObject.GetType().FullName)); } ITreeListViewHoster treeListHoster = _TreeListHoster; try { using (MB.WinBase.WaitCursor cursor = new MB.WinBase.WaitCursor(this)) { if (_ClientRuleObject.ClientLayoutAttribute.CommunicationDataType == CommunicationDataType.DataSet) { throw new MB.Util.APPException("树型浏览主界面暂时不支持DataSet 的绑定", MB.Util.APPMessageType.SysErrInfo); } else { IList lstDatas = null; try { lstDatas = _ClientRuleObject.GetObjects((int)_ClientRuleObject.MainDataTypeInDoc, queryParams); } catch (Exception ex) { throw MB.Util.APPExceptionHandlerHelper.PromoteException(ex, "DefaultTreeListViewForm.GetObjects 出错!"); } if (_BindingSource == null || _RecreateTreeAfterSorting) { IBindingList bl = _ClientRuleObject.CreateMainBindList(lstDatas); _BindingSource = new MB.WinBase.Binding.BindingSourceEx(); _BindingSource.ListChanged += new ListChangedEventHandler(_BindingSource_ListChanged); _BindingSource.DataSource = bl; treeListHoster.CreateTreeListViewDataBinding(trvLstMain, _BindingSource); if (trvLstMain.Nodes.Count > 0) { trvLstMain.Nodes[0].Expanded = true; trvLstMain.FocusedNode = trvLstMain.Nodes[0]; } _RecreateTreeAfterSorting = false; } else { treeListHoster.RefreshTreeListData(trvLstMain, lstDatas); } } panTitle.Visible = false; } } catch (MB.Util.APPException aex) { throw aex; } catch (Exception ex) { throw MB.Util.APPExceptionHandlerHelper.PromoteException(ex, "在浏览窗口DefaultTreeListViewForm_Load 时出错!"); } }
/// <summary> /// 设置控件数据源。 /// </summary> /// <param name="clientRule"></param> /// <param name="dataSource"></param> public void SetDataSource(IClientRuleQueryBase clientRule, object dataSource) { IList lstDatas = dataSource as IList; if (lstDatas == null) { throw new MB.Util.APPException("目前树型浏览列表只支持IList 数据类型", MB.Util.APPMessageType.SysErrInfo); } _TreeListHoster = clientRule as ITreeListViewHoster; if (_TreeListHoster == null) { throw new MB.Util.APPException("获取树型列表数据的业务对象必须继承 ITreeListViewHoster 接口。", MB.Util.APPMessageType.SysErrInfo); } MB.WinBase.Binding.BindingSourceEx bindingSource = new MB.WinBase.Binding.BindingSourceEx(); bindingSource.DataSource = dataSource; _TreeListHoster.CreateTreeListViewDataBinding(trvLstMain, bindingSource); trvLstMain.DataSource = lstDatas; //add by aifang 2012-04-17 数据绑定无效,重新对控件数据源赋值 trvLstMain.RefreshDataSource(); if (trvLstMain.Nodes.Count > 0) { trvLstMain.Nodes[0].Expanded = true; trvLstMain.FocusedNode = trvLstMain.Nodes[0]; } }