国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 栖霞市| 紫云| 华安县| 北票市| 梨树县| 随州市| 乌鲁木齐县| 伊吾县| 万全县| 紫金县| 扎兰屯市| 南投县| 南郑县| 昭苏县| 莆田市| 佛教| 遂川县| 西丰县| 白沙| 交口县| 三台县| 义乌市| 马龙县| 额济纳旗| 宁乡县| 黄陵县| 康定县| 汝南县| 桦川县| 秦安县| 获嘉县| 西乌| 绥中县| 广东省| 尼木县| 阜新| 永顺县| 上杭县| 大石桥市| 吉隆县| 高唐县|