| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3130 人关注过本帖, 1 人收藏
标题:TreeView1.nodes.Add中提示集合中的关键字不唯一?(难!无人能解决)[提供 ...
只看楼主 加入收藏
xzqsml
Rank: 2
等 级:论坛游民
帖 子:41
专家分:47
注 册:2008-6-15
结帖率:90.91%
收藏(1)
已结贴  问题点数:7 回复次数:8 
TreeView1.nodes.Add中提示集合中的关键字不唯一?(难!无人能解决)[提供源码附件]
以下代码:

Private Sub CC()
OpenConn
Dim rs As Recordset
Dim m
Dim SQL
Dim nodes As Node
'TreeView1.LineStyle = tvwTreeLines

 

Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "select * from CC", cn, 2, 2
Dim i As Integer
Dim j As Integer
Dim zxs
TreeView1.ImageList = TreeImages
With rs
'RS.Close
  ' Set RS = Nothing

  
    If .RecordCount <> 0 Then
        For j = 0 To 5
            .Close
            .Open "select * from CC", cn, 2, 2
            For i = 1 To .RecordCount
                If .Fields("treerelationship") <> "" Then
                  
                    TreeView1.nodes.Add CStr(.Fields("treerelative")), tvwChild, .Fields("treekey"), .Fields("用户姓名"), CInt(.Fields("treeimgindex"))
                Else
                    TreeView1.nodes.Add , , .Fields("treekey"), .Fields("用户姓名"), CInt(.Fields("treeimgindex")) '此处提示集合中的关键字不唯一
                End If
               .MoveNext
            Next i
        Next j
    End If
End With

For m = 1 To TreeView1.nodes.Count
TreeView1.nodes(m).Expanded = True '

Next



         
CloseConn      

End Sub



Access数据库中数据如下:
TreeRelative  TreeRelationship  TreeKey  用户姓名  TreeIMGIndex
 空        空        CC    在线用户   1
 CC                1                 张三   张三     1


CC.rar (12.14 KB)
提供源码附件

[ 本帖最后由 xzqsml 于 2010-1-23 11:56 编辑 ]
搜索更多相关主题的帖子: 提示 关键 附件 源码 Add 
2010-01-23 09:45
xzqsml
Rank: 2
等 级:论坛游民
帖 子:41
专家分:47
注 册:2008-6-15
收藏
得分:0 
难道真的没有人回答吗?
2010-01-23 13:10
xzqsml
Rank: 2
等 级:论坛游民
帖 子:41
专家分:47
注 册:2008-6-15
收藏
得分:0 
懂TreeView控件朋友,能不能写一个类似的代码.
要要求二级目录即可!能从数据库中动态取数更新TreeView内容
2010-01-23 16:08
bczgvip
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:66
帖 子:1310
专家分:5312
注 册:2009-2-26
收藏
得分:0 
程序代码:
Private Sub Form_Load()
OpenConn

Dim rs As Recordset
Dim m
Dim SQL
Dim tvNodes As nodes
Dim node1 As Node
'TreeView1.LineStyle = tvwTreeLines

Set tvNodes = TreeView1.nodes
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "select * from CC", cn, 2, 2
Dim i As Integer
Dim j As Integer

With rs
    .MoveFirst
    For i = 1 To .RecordCount
        If IsNull(.Fields("TreeRelationship")) Or 0 = .Fields("TreeRelationship") Then  'TreeRelationshipConstants
            Set node1 = tvNodes.Add(, tvwLast, , .Fields("用户姓名"), CInt(.Fields("TreeIMGIndex")))
        Else
            Set node1 = tvNodes.Add(CInt(.Fields("TreeRelationship")), tvwChild, , .Fields("用户姓名"), CInt(.Fields("TreeIMGIndex")))
        End If
       .MoveNext
    Next i
End With

For m = 1 To TreeView1.nodes.Count
    TreeView1.nodes(m).Expanded = True '
'TreeView1.ShowHint = False
Next

CloseConn
End Sub
2010-01-24 01:12
anjing572
Rank: 1
等 级:新手上路
帖 子:28
专家分:1
注 册:2007-7-7
收藏
得分:1 
         Set node1 = tvNodes.Add(CInt(.Fields("TreeRelationship")), tvwChild, , .Fields("用户姓名"), CInt(.Fields("TreeIMGIndex")))
还是不对呀
2010-01-24 20:12
bczgvip
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:66
帖 子:1310
专家分:5312
注 册:2009-2-26
收藏(1)
得分:0 
程序代码:
Private Sub Form_Load()
OpenConn

Dim rs As Recordset
Dim m
Dim SQL
Dim tvNodes As Nodes
Dim node1 As Node
'TreeView1.LineStyle = tvwTreeLines

Set tvNodes = TreeView1.Nodes
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "select * from CC", cn, 2, 2
Dim i As Integer
Dim j As Integer

With rs
    .MoveFirst
    For i = 1 To .RecordCount
        If IsNull(.Fields("TreeRelative")) Or vbNullString = .Fields("TreeRelative") Then 'TreeRelationshipConstants
            Set node1 = tvNodes.Add(, tvwLast, .Fields("TreeKey"), .Fields("用户姓名"), CInt(.Fields("TreeIMGIndex")))
        Else
            Set node1 = tvNodes.Add(CStr(.Fields("TreeRelative")), tvwChild, , .Fields("用户姓名"), CInt(.Fields("TreeIMGIndex")))
        End If
       .MoveNext
    Next i
End With

For m = 1 To TreeView1.Nodes.Count
    TreeView1.Nodes(m).Expanded = True '
'TreeView1.ShowHint = False
Next

CloseConn
End Sub
2010-01-25 03:43
xzqsml
Rank: 2
等 级:论坛游民
帖 子:41
专家分:47
注 册:2008-6-15
收藏
得分:0 
提示,对象关闭时不允许操作,错在哪呢??
2010-01-25 08:47
bczgvip
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:66
帖 子:1310
专家分:5312
注 册:2009-2-26
收藏
得分:6 
CC.zip (11.89 KB)
2010-01-25 10:09
frank_tao78
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:69
专家分:143
注 册:2010-1-11
收藏
得分:0 
回复 7楼 xzqsml
这个好像和我现在碰到的问题一样:对象关闭时,不允许操作
2010-01-27 13:43
快速回复:TreeView1.nodes.Add中提示集合中的关键字不唯一?(难!无人能解决) ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030529 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved