`
SE7EN
  • 浏览: 3170 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

TV (treeview)

阅读更多

//========================================
//Envrionment to hold Listeners
//========================================
tv_listeners = new Array() ;
function listener( type , handler )   {
 this.type = type ;
 this.handler = handler ;
 this.id = tv_listeners.length ;
 tv_listeners[ tv_listeners.length ] = this ;
}

function addListener( type , handler )  {
    new listener( type , handler ) ; 
 }
//=== END =====

//=========================================
// Hold the top item
//=========================================
tv_topnodeitem = null ;
//===== END =======

//=========================================
//Hold nodeitems , and supply a nodeitem Register
//=========================================
nodeitems = new Array() ;
function nodeitemRegister( obj )   {
    nodeitems[ nodeitems.length ] = obj ;
 return nodeitems.length - 1 ;
}
//=== END =======

//=================================
//Custom a stack
//Class         : stack
//metheds    :  get()
//                    put( obj )
//=================================
function stack() {
    this.value = new Array() ;
 this.cursor = 0 ;
}

function stack_get()  {
     this.cursor = this.cursor - 1 ;
  return this.value[ this.cursor ] ;
}

function stack_put( obj )   {
      this.value[ this.cursor ] = obj ;
      this.cursor = this.cursor + 1 ;
}

stack.prototype.get = stack_get ;
stack.prototype.put = stack_put ;
//=======END ==========

//=========================================
// Define a public stack
//=========================================
userstack = new stack() ;
//====== END ===========

//=========================================
//Image List
//=========================================
treeview_box_0_none = "images/4_clos.gif"  ;
treeview_box_0_line = "images/4_none.gif" ;
treeview_box_2_open = "images/2_open.gif" ;
treeview_box_2_none = "images/2_none.gif" ;
treeview_box_2_close = "images/2_clos.gif" ;
treeview_box_1_open = "images/3_open.gif" ;
treeview_box_1_none = "images/3_none.gif" ;
treeview_box_1_close = "images/3_clos.gif" ;

//===============================================
//Class : nodeitem
//status------------------------1:two-direction       0:nobox       0: disactivite
//                              2:three-0direction     1:close-box   1: activite
//                                                    2:open-box                   
//===============================================
function nodeitem( parentkey , key , lable , img )  {
    this.lable = lable ;
 this.key = key ;
    this.parent = findNode( parentkey ) ;
 if( this.parent != null )  {
     aa = this.parent.status ;
     if( aa.substring( 1 , 2 ) == "0" )
         this.parent.status = aa.substring( 0 , 1 ) + "1" + aa.substring( 2 , 3 ) ;
     if( this.parent.maxsubitem != null )
         this.parent.maxsubitem.status = "2" + this.parent.maxsubitem.status.substring( 1 , 3 ) ;
        this.parent.subitems[ this.parent.subitems.length ] = this ;
        this.parent.maxsubitem = this ;
    }
    else  {
     if( tv_topnodeitem != null )   {
       alert( "不能有两个顶项!" ) ;
    return ;
        }
        tv_topnodeitem = this ;
    }
  
 this.img = img ;
 this.tag = null ;
    this.status = "100" ;
 this.subitems = new Array() ;
 this.maxsubitem = null ;
    this.id = nodeitemRegister( this ) ;

 //**********************
 this.questionId = 0;
 this.description = "";
 //this.url = null;
 //**********************
 
 //added by msb for the sort and move up/down
 /*if ( this == tv_topnodeitem )
 {
  this.nodeIndex = 0;
 } else {
  this.nodeIndex = this.parent.subitems.length;
 }*/
 //end added

}

//added by msb for the sort and move up/down
function nodeitem_moveUp() {
 if (this == tv_topnodeitem) return; //topitem

 ssubitems = this.parent.subitems;
 for ( i=0; i<ssubitems.length; i++ ) {
  if( ssubitems[i] == this ) {
   break;
  }
 }
 if (i==0) return;
 ssubitems[i] = ssubitems[i-1];
 ssubitems[i-1] = this;
 if (i==ssubitems.length-1) {
  ssubitems[i-1].status = "2" + ssubitems[i-1].status.substring(1, 3);
  ssubitems[i].status = "1" + ssubitems[i].status.substring(1, 3);
 }
 /*
 itemTemp = this;
 ssubitems[this.nodeIndex-1] */
/* for ( i=0; i<ssubitems.length; i++ ) {
  if( ssubitems[i] != null && ssubitems[i].nodeIndex == (this.nodeIndex-1) )
   previousitem = ssubitems[i]
 }
 previousitem.nodeIndex = this.nodeIndex;
 this.nodeIndex = this.nodeIndex -1;
 swap(this,previousitem);
*/
 //label_on_click(this.id);
 this.parent.refresh();

 lable_on_click(this.id);
}//moveUp()

function nodeitem_moveDown() {
 if (this == tv_topnodeitem) return; //topitem
 
 ssubitems = this.parent.subitems;
 for ( i=0; i<ssubitems.length; i++ ) {
  if( ssubitems[i] == this ) {
   break;
  }
 }
 if (i==ssubitems.length-1) return;
 ssubitems[i] = ssubitems[i+1];
 ssubitems[i+1] = this;
 if (i==ssubitems.length-2) {
  ssubitems[i+1].status = "1" + ssubitems[i+1].status.substring(1, 3);
  ssubitems[i].status = "2" + ssubitems[i].status.substring(1, 3);
 }

 this.parent.refresh();
  
 lable_on_click(this.id);
}//moveDown()

/*function swap (item1, item2) {
 nodeitems[item1.id] = item2;
 nodeitems[item2.id] = item1;
 idTemp = item1.id;
 item1.id = item2.id;
 item2.id = idTemp;
}*/

//end added

function nodeitem_setTag( obj ) {
    this.tag = obj ;
}

function nodeitem_getTag() {
    return this.tag ;
}

function nodeitem_show()  {
 str = "<span id = 'preface" + this.id + "'><table border='0' cellspacing='0' cellpadding='0'><tr><td>" ;
    str_f = "" ;
    for( j = this.parent ; j != null ; j = j.parent )  {
     if( j.status.substring( 0 , 1 ) == 1 )
      str_f = "<img src = '" + treeview_box_0_none + "' align='absmiddle'>" + str_f ;
        else
      str_f = "<img src = '" + treeview_box_0_line + "' align='absmiddle'>" + str_f ;
    }
    str = str + str_f ;
    str += "<img id = 'box" + this.id + "' nodeid = '" + this.id + "' src = '" ;
    switch( this.status.substring( 0 , 2 ) )   {
        case "10" : str += treeview_box_1_none ; break ;
        case "11" : str += treeview_box_1_close ; break ;
        case "12" : str += treeview_box_1_open ; break ;
        case "20" : str += treeview_box_2_none ; break ;
        case "21" : str += treeview_box_2_close ; break ;
        case "22" : str += treeview_box_2_open ; break ;
    }
    str += "' align='absmiddle' onclick='box_on_click(this)'>" ;
    if( this.img == "" )
     str += this.img ;
    else
     str += "<img src = '" + this.img + "' align='absmiddle' width='16' height='16'>" ;
    str += "</td><td><table border='0' cellspacing='1' cellpadding='1' style='font-size:9pt; color:#333333' id='lablePanel" + this.id + "'><tr><td ondblclick = 'lable_on_dblclick(" + this.id + ")' onclick='lable_on_click(" + this.id + ")' style='cursor:hand' id='f_lablePanel" + this.id + "' nowrap>" + this.lable + "</td></tr></table></td></tr></table>" ; 
 str += "</span><span id = 'tv_panel_" + this.id + "' style='display:" ;
 if( this.status.substring( 1 , 2 ) == '2' )
    str += "" ;
 else
    str += "none" ;
 
    str += "'></span>" ;
 if( this.parent == null ) 
      for(var i in document.all){
          if (document.all[i].tagName == "BODY")
          {
        document.all[i].insertAdjacentHTML( "AfterBegin" , str ) ;
              break
          }
       }
 else  
 document.all( "tv_panel_" + this.parent.id ).insertAdjacentHTML( "BeforeEnd" , str ) ;
    for( m = 0 ; m < this.subitems.length ; m ++ )
    if( this.subitems[ m ] != null )  {
     userstack.put( m ) ;
     this.subitems[ m ].show() ;
     m = userstack.get() ;
    }
}

function nodeitem_refresh()  {
 str = "<table border='0' cellspacing='0' cellpadding='0'><tr><td>" ;
    str_f = "" ;
    for( j = this.parent ; j != null ; j = j.parent )  {
     if( j.status.substring( 0 , 1 ) == 1 )
     str_f = "<img src = '" + treeview_box_0_none + "' align='absmiddle'>" + str_f ;
        else
     str_f = "<img src = '" + treeview_box_0_line + "' align='absmiddle'>" + str_f ;
    }
 str = str + str_f ;
    str += "<img id = 'box" + this.id + "' nodeid = '" + this.id + "' src = '" ;
    switch( this.status.substring( 0 , 2 ) )   {
         case "10" : str += treeview_box_1_none ; break ;
         case "11" : str += treeview_box_1_close ; break ;
         case "12" : str += treeview_box_1_open ; break ;
         case "20" : str += treeview_box_2_none ; break ;
         case "21" : str += treeview_box_2_close ; break ;
         case "22" : str += treeview_box_2_open ; break ;
    }
    str += "' align='absmiddle' onclick='box_on_click(this)'>" ;
    if( this.img == "" )
     str += this.img ;
    else
     str += "<img src = '" + this.img + "' align='absmiddle' width='16' height='16'>" ;
    str += "</td><td><table border='0' cellspacing='1' cellpadding='1' style='font-size:9pt; color:#333333' id='lablePanel" + this.id + "'><tr><td ondblclick = 'lable_on_dblclick(" + this.id + ")' onclick='lable_on_click(" + this.id + ")' style='cursor:hand' id='f_lablePanel" + this.id + "' nowrap>" + this.lable + "</td></tr></table></td></tr></table>" ; 
 document.all( "preface" + this.id ).innerHTML = str ;
    document.all( "tv_panel_" + this.id ).innerHTML = "" ;
 for( m = 0 ; m < this.subitems.length ; m ++ )
    if( this.subitems[ m ] != null )  {
     userstack.put( m ) ;
     this.subitems[ m ].show() ;
     m = userstack.get() ;
       }
}
function nodeitem_remove()  {
    pparent = this.parent ;
 if( pparent == null )   {
        removenodeitem( this.id ) ;
        for(var i in document.all){
           if (document.all[i].tagName == "BODY")
             {
      document.all[i].innerHTML = "" ;
               break
             }
          }
  return ;
 }
 lastsubitem = null ;
 for( i = 0 ; i < pparent.subitems.length ; i ++ )
    if( pparent.subitems[ i ] != null ) 
     if ( pparent.subitems[ i ] == this )
         pparent.subitems[ i ] = null ;
           else
         lastsubitem = pparent.subitems[ i ] ;

    pparent.maxsubitem = lastsubitem ;
 if( lastsubitem == null )  
        pparent.status = pparent.status.substring( 0 , 1 ) + "0" + pparent.status.substring( 2 , 3 ) ;
    else  
     pparent.maxsubitem.status = "1" + pparent.maxsubitem.status.substring( 1 , 3 ) ;
     removenodeitem( this.id ) ;

 //added by msb for move up/down
 arrTemp = new Array();
 j = 0;
 for ( i=0; i<pparent.subitems.length; i++ ) {
  if ( pparent.subitems[i] != null ) {
   arrTemp[j] = pparent.subitems[i];
   j++;
  }
 }
 this.parent.subitems = arrTemp;
 //end added

  pparent.refresh() ;
  //tv_topnodeitem.refresh() ;
}

function removenodeitem( id )   {
    curitem = nodeitems[ id ] ;
 nodeitems[ id ] = null ;
 for( m = 0 ; m < curitem.subitems.length ; m ++ )
      if( curitem.subitems[ m ] != null )   {
     userstack.put( m ) ;
     removenodeitem( curitem.subitems[ m ].id ) ;
     m = userstack.get() ;
       }
}

function nodeitem_boxclick()  {
     if( this.status.substring( 1 ,2 ) == "0" )
       return ;
  if( this.status.substring( 1 ,2 ) == "1" )  
        this.open() ;
  else 
        this.close() ;
}

function nodeitem_close()  {
     this.status = this.status.substring( 0 , 1 ) + "1" + this.status.substring( 2 , 3 ) ;
     document.all( "tv_panel_" + this.id ).style.display = "none" ;
     eval( "document.all( 'box' + this.id ).src = treeview_box_" + this.status.substring( 0 , 1 ) +"_close" ) ;
}

function nodeitem_open()  {
     this.status = this.status.substring( 0 , 1 ) + "2" + this.status.substring( 2 , 3 ) ;
     document.all( "tv_panel_" + this.id ).style.display = "" ;
     eval( "document.all( 'box' + this.id ).src = treeview_box_" + this.status.substring( 0 , 1 ) +"_open" ) ;
}

//added by msb for the move up/down
nodeitem.prototype.moveUp = nodeitem_moveUp;
nodeitem.prototype.moveDown = nodeitem_moveDown;
//end added

nodeitem.prototype.show = nodeitem_show ;
nodeitem.prototype.refresh = nodeitem_refresh ;
nodeitem.prototype.boxclick = nodeitem_boxclick ;
nodeitem.prototype.close = nodeitem_close ;
nodeitem.prototype.open = nodeitem_open ;
nodeitem.prototype.remove = nodeitem_remove ;
nodeitem.prototype.setTag = nodeitem_setTag ;
nodeitem.prototype.getTag = nodeitem_getTag ;

//==========================================================
// Public Methods
//==========================================================
function showTV()  {
     tv_topnodeitem.show() ;
}

function findNode( key )   {
 pppp = null;
    for( i = 0 ; i < nodeitems.length ; i ++ ) {
    if( nodeitems[ i ] != null ) {
       if( nodeitems[ i ].key == key ) {
          pppp = nodeitems[ i ] ;
    }
    }
 }
    return pppp ;
}

function addNode(  parentkey , key , lable , img  )   {
    return new nodeitem( parentkey , key , lable , img ) ;
}

function deleteNode(  key )   {
    curNode = findNode( key ) ;
 if( curNode == null )
   return false ;
    curNode.remove() ;
    return true ;
}
//====== END ================

//===========================================================
// Events
//===========================================================
function box_on_click( obj )  {
    nodeitems[ obj.nodeid ].boxclick() ;
}

tv_curlable = null ;
tv_curlable_f = null ;

function lable_on_click( id )  {
       key = nodeitems[ id ].key ;
       if( nodeitems[ id ].parent == null )
       parentkey = "" ;
       else
       parentkey = nodeitems[ id ].parent.key ;
          
    if( tv_curlable != null )  {
     tv_curlable.bgColor = "transparent" ;
     tv_curlable.style.color = "#333333" ;
     tv_curlable_f.bgColor = "transparent" ;
       }
        tv_curlable = document.all("lablePanel"+id) ;
     tv_curlable.bgColor = "#000000" ;
     tv_curlable.style.color = "#FFFFFF" ;
        tv_curlable_f = document.all("f_lablePanel"+id) ;
     tv_curlable_f.bgColor = "#888888" ;

    for( i = 0 ; i < tv_listeners.length ; i ++ ) 
       if( tv_listeners[ i ].type == "click" )  {
      h = tv_listeners[ i ].handler ;
      eval( h + "( '" + key + "' , '" + parentkey + "' ) ; " ) ;
           }

}

function lable_on_dblclick( id ) {
  key = nodeitems[ id ].key ;
       if( nodeitems[ id ].parent == null )
       parentkey = "" ;
       else
       parentkey = nodeitems[ id ].parent.key ;
         
    if( tv_curlable != null )  {
     tv_curlable.bgColor = "transparent" ;
     tv_curlable.style.color = "#333333" ;
     tv_curlable_f.bgColor = "transparent" ;
       }
        tv_curlable = document.all("lablePanel"+id) ;
     tv_curlable.bgColor = "#000000" ;
     tv_curlable.style.color = "#FFFFFF" ;
        tv_curlable_f = document.all("f_lablePanel"+id) ;
     tv_curlable_f.bgColor = "#888888" ;
    for( i = 0 ; i < tv_listeners.length ; i ++ ) 
       if( tv_listeners[ i ].type == "dblclick" )  {
      h = tv_listeners[ i ].handler ;
      eval( h + "( '" + key + "' , '" + parentkey + "' ) ; " ) ;
           }
}

分享到:
评论

相关推荐

    VB TreeView控件相关知识

    Dim tv As TreeView Dim ni As Node Set tv = Treeview ' 创建顶级节点 - 水果 Set ni = tv.Nodes.Add(, , "水果") ni.ImageIndex = 0 ' 使用ImageList中的0号图像 ni.SelectedImageIndex = 0 ' 选中时显示...

    TreeView安装在VS2003

    TreeView tv = new TreeView(); tv.Nodes.Add(new TreeNode("父节点")); tv.Nodes[0].Nodes.Add(new TreeNode("子节点1")); tv.Nodes[0].Nodes.Add(new TreeNode("子节点2")); ``` 3. **事件处理**:TreeView控件有...

    实现treeview的操作

    在Microsoft Foundation Class (MFC)库中,TreeView控件是一个常用元素,用于显示层次结构数据。这个控件在用户界面中通常表现为一个树状结构,其中每个节点代表一个项目,可以有子节点或子项。在VC++环境中,实现对...

    TreeView控件使用技巧

    2. 在应用窗口中添加DataWindow控件(如dw_3和dw_4)和TreeView控件(如TV_1)。 3. 修改DW_3的属性,将Datawindow object name设置为已经存在的DW_date,用于生成树视图项,同时将其设为不可见。 4. 修改DW_4的属性...

    pb treeview控件的使用技巧

    在应用中新建一个应用窗口`W_1`,并在该窗口上添加两个DataWindow控件`dw_3`、`dw_4`以及一个TreeView控件`TV_1`。 3. **配置DataWindow控件`dw_3`** 修改`dw_3`的属性: - `Datawindow object name`:设置为...

    Using TreeControl (TreeView) under Win32 API

    这个函数需要提供`TV_INSERTSTRUCT`结构,包含新节点的信息,如父节点的句柄、文本、图标索引等。为了管理节点,我们还需要维护一个数据结构,通常是一个链表或哈希表,来存储每个节点的额外信息。 对于节点的图标...

    PB treeview 控件设置背景图片

    lg_graphics-&gt;DrawImage(li_image, 0, 0, tv_treeview.width, tv_treeview.height) delete lg_graphics } ``` 5. 清理: 在窗体的Close事件中,记得清理GDI+资源。 ```pb on_close() { delete li_image ...

    C#递归遍历文件夹显示在TreeView

    private void relateTreeView(TreeView tv, string path) { // 清空TreeView,准备添加新的节点 tv.Nodes.Clear(); // 添加根节点 tv.Nodes.Add(new TreeNode()); // 解析路径并设置根节点的文本和名称 string...

    TreeView_carriednpq_DEMO_Vc_源码

    每个树节点都有一个`TV_ITEM`结构,其中包含了节点文本、图像索引、子节点数量等信息。 3. **设置图标**:通过`SetImageList`函数设置图像列表,这样每个节点就可以显示对应的图标。图像列表通常包含正常状态和选中...

    asp.net用代码帮东treeview

    tv = TreeView1; AddTree(0, (TreeNode)null); } ``` #### 5. **递归构建节点** - `AddTree()` 方法是递归函数,用于根据数据构建TreeView的节点。 - 使用`DataView`进行行过滤,只获取父ID等于指定ID的行。 ...

    treeview动态生成

    CreateTree(0, tvShow.Nodes); } } private void CreateTree(int belong, TreeNodeCollection collection) { DataTable ds = MenuService.SelectAllFather(belong); foreach (DataRow dr in ds.Rows) { ...

    TREEVIEW控件TV20.js及视频讲解part1

    TREEVIEW控件TV20.js及视频讲解part1,没办法,只能上传小于15M的文件,把PART1和PART2放在一个文件夹下解压

    Treeview绑定数据库

    1. `tv.Nodes.Clear()`:清除`TreeView`中的所有现有节点,为新的数据绑定做准备。 2. 创建一个名为“全部员工”的根节点:`TreeNode n = new TreeNode(); n.Text = "全部员工"; this.TreeView1.Nodes.Add(n);` 这...

    JavaScript树\利用JavaScript实现树型结构的TreeView类

    var tv = new TreeView("tv"); // 创建TreeView实例 tv.add(0, 1, "目录一"); // 添加根节点 tv.add(1, 2, "目录二"); // 添加子节点 tv.refresh(); // 刷新显示 ``` - **变量命名与注释**:代码中存在部分非标准...

    delphi中TreeView的一些应用

    例如,你可以为`TreeView`分配一个名为`TV1`的变量,并关联一个`ImageList`控件(如`ImageList1`),以在节点旁边显示图像。这可以通过将`TV1.Images`属性设置为`ImageList1`来实现。 ### `TreeView`控件的应用实例...

    PB中TreeView控件的深度优化搜索算法程序

    此函数接受三个参数:`tv_tree`为TreeView对象,`findby`为布尔值,指示搜索模式(标签或数据),`data`为搜索的目标值。 函数内部,首先初始化一个动态数组`ll_hdl[]`用于存储树节点的句柄,以及一个整型变量`li_...

    .NET treeview控件使用

    也可以通过代码动态创建,如`TreeView tv = new TreeView();`。 2. 添加节点:可以通过`TreeNode`类创建和添加节点。例如,`TreeNode node = new TreeNode("父节点"); tv.Nodes.Add(node);`。子节点可通过`Add()`...

    用js脚本控制asp.net下treeview的NodeCheck的实现代码

    为了确保以上函数能正确执行,需要使用一些辅助函数来判断元素类型或者获取 TreeNode、节点、父节点等信息,比如`IsCheckBox`、`TV2_GetTreeById`、`TV2_GetNode`、`TV2_GetParentNode`、`TV2_GetChildNodes`、`TV2i...

    treeview用法

    节点由`HTREEITEM`标识,并通过`TV_INSERTSTRUCT`结构插入到树视图中。 2. **添加和管理节点** - **插入节点**:使用`TreeView_InsertItem`函数可以向TreeView中插入新的节点。你需要提供一个`TVINSERTSTRUCT`结构...

    C# TreeView使用一点方法

    1. 遍历数据集的每一行,当`Rows[i][1]`的值为"..."时,创建一个`TreeNode`作为根节点,设置其`Value`和`Text`属性,并添加到`tv.Nodes`(`TreeView`的根节点集合)中。 2. 同样,创建一个名为"..."的子节点并添加到...

Global site tag (gtag.js) - Google Analytics