国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

用TreeView顯示數(shù)據(jù)通用方法

2024-07-21 02:16:09
字體:
供稿:網(wǎng)友

public void treeviewdata(dataset ds,string    textcolumnname,string parentcolumnname,string tagcolumnname)

{

 mytreedata root = new mytreedata();
    mytreedata child = null;
    for (i = 0 ; i < ds.tables[0].rows.count; ++i)
    {
     child = new mytreedata(ds.tables[0].rows[i][textcolumnname].tostring(),ds.tables[0].rows[i][tagcolumnname],ds.tables[0].rows[i][parentcolumnname]);
     root.add(child);
    }

    root.showtree(tv);
}



 /// <summary>
 /// 樹型節(jié)點(diǎn)數(shù)據(jù)類
 /// </summary>
 public class mytreedata
 {
  public mytreedata()
  {
  }


  public mytreedata(string name)
  {
   name = name;
  }


  public mytreedata(string name,object tag,object parent)
  {
   name = name;
   tag = tag;
   parent = parent;
  }


  /// <summary>
  /// 子數(shù)據(jù)集合
  /// </summary>
  private mytreedatacollection child = new mytreedatacollection();


  /// <summary>
  /// 數(shù)據(jù)對(duì)象
  /// </summary>
  public object tag = null;

  /// <summary>
  /// 名稱
  /// </summary>
  public string name = "";

  /// <summary>
  /// 父親
  /// </summary>
  public object parent = null;


  /// <summary>
  /// 添加子數(shù)據(jù)
  /// </summary>
  /// <param name="child">子數(shù)據(jù)</param>
  public void add(mytreedata child)
  {
   int i;
   for (i =  this.child.count - 1; i >= 0;--i)
   {
    if (convert.toint32(this.child[i].parent) == convert.toint32(child.tag) )
    {
     child.child.add(this.child[i]);
     this.child.removeat(i);
    }
   }
   mytreedata parent = findparent(this,child);
   if (parent == null)
   {
    this.child.add(child);
   }
   else
   {
    parent.child.add(child);
   }
  }


  /// <summary>
  /// 查找父親數(shù)據(jù)
  /// </summary>
  /// <param name="child">子數(shù)據(jù)</param>
  /// <returns>父親數(shù)據(jù)或者null</returns>
  public mytreedata findparent(mytreedata parent,mytreedata child)
  {
   int i;
   for (i = 0; i < parent.child.count; ++i)
   {
    if (convert.toint32(parent.child[i].tag) == convert.toint32(child.parent))
    {
     return parent.child[i];
    }
    mytreedata temp = findparent(parent.child[i],child);
    if (temp != null)
    {
     return temp;
    }
   }
   return null;
  }


  /// <summary>
  /// 將子數(shù)據(jù)顯示到treeview
  /// </summary>
  /// <param name="tv">treeview</param>
  public void showtree(treeview tv)
  {
   int i;
   treenode tn = null;
   for (i = 0 ; i < this.child.count; ++i)
   {
    tn = tv.nodes.add(this.child[i].name);
    tn.tag = this.child[i].tag;
    showtree(tn,this.child[i]);
   }
  }


  /// <summary>
  /// 遞歸顯示數(shù)據(jù)
  /// </summary>
  /// <param name="tn">節(jié)點(diǎn)</param>
  /// <param name="child">數(shù)據(jù)</param>
  private void showtree(treenode tnparent,mytreedata child)
  {
   int i;
   treenode tn = null;
   for (i = 0 ; i < child.child.count; ++i)
   {
    tn = tnparent.nodes.add(child.child[i].name);
    tn.tag = child.child[i].tag;
    showtree(tn,child.child[i]);
   }
  }
   

  /// <summary>
  /// 樹型節(jié)點(diǎn)集合類
  /// </summary>
  internal class mytreedatacollection : addcollectionbase
  {
   public mytreedatacollection()
   {
   }
    
   public mytreedata this[int index]
   {
    get
    {
     return (mytreedata)list[index];

    }
   }
  }
 }



發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 五大连池市| 阳城县| 长宁县| 康平县| 西乌| 托克托县| 东乌珠穆沁旗| 康保县| 旌德县| 垫江县| 任丘市| 上虞市| 汨罗市| 张家口市| 大英县| 罗田县| 福鼎市| 徐水县| 平山县| 织金县| 金华市| 江油市| 长葛市| 平谷区| 安顺市| 西和县| 五家渠市| 长葛市| 缙云县| 林周县| 西贡区| 临西县| 滦南县| 杂多县| 高要市| 翼城县| 洪湖市| 贡嘎县| 贡嘎县| 枣强县| 陵川县|