日期:2008-09-15  浏览次数:20416 次


///如未特别说明,本人所发表的技术文章都为原创, 任何人引用都请注明出处,并包含本声明
///作者: CSDN网名alias88,邮件:alias88@163.com,QQ:63343 欢迎加我 :)


  此树可以绑定到数据源,意味着可随着绑定管理器同步操作,

  例如position改变自动选择结点,反过来亦然,选择不同的结点将改变绑定管理器的position,而且数据操作也能同步于绑定管理器,您在DataGrid中的改变将即时反映在树中......

还有一个特点,对数据结构没有要求,它总是能正确地将您的数据以树结构展现出来,下图中,如果使用搜索功能筛选出任一部分数据出来,左边的树形结构也将是正确的



  使用方法和例图:

  TreeView1.AllowDrop =true;
  this.TreeView1.SetDataBinding (this.UserDataSet ,"会计科目"  ,"上级编号","科目编号","科目名称",null);
















using System;







using System.Collections;







using System.ComponentModel;







using System.Drawing;







using System.Data;







using System.Windows.Forms;








 


 



using upLibrary.upCommon ;







using upLibrary.upReflect;







using upLibrary.upControls ;







using System.Diagnostics;







using upSystem.upData ;








 


 



namespace upSystem.upControls







{







  /// <summary>







  /// 一个实现了数据绑定的树







  /// </summary>







  public class upTreeView : upTreeViewBase







  {







    private object dataSource;







    private string dataMember;







    private string parentIDColumn,idColumn,textColumn;







    private object[] topID=null;







    







    private PropertyDescriptorCollection propertys=null;







    private PropertyDescriptor parentIDProperty,idProperty,textProperty;







      







    private CurrencyManager bindingManager=null;







    private IBindingList  bindingList=null;







    private bool dataSourceEvent,treeViewEvent;







    private DataView dataView=null;







    private upSystem.upCommon.upStack stack=new upSystem.upCommon.upStack ();







    







    private System.ComponentModel.Container components = null;







    public event System.EventHandler DataSourceChanged;







    private System.Windows.Forms.ContextMenu cntMenu;








 


 



    public upTreeView()







    {







      InitializeComponent();







      this.cntMenu = new System.Windows.Forms.ContextMenu();







      MenuItem mnu;







      mnu=cntMenu.MenuItems.Add ("&O展开");







      mnu.Click +=new EventHandler(mnu_Click);







      mnu=cntMenu.MenuItems.Add ("&C折叠");







      mnu.Click +=new Ev