如何在VB中读取treeview最内层的节点的值
做一个对excel自动评分(自动修改题目要求)系统
1、通过combo1查找数据库(PP.mdb有源码)的代码(自定义的函数的信息),并且单击增加评分条件按钮,把combo1内的数据赋值给评分节点的子节点
2、把treeview最内层节点值(即评分下节点的值)读取,并给它赋值给某变量或数组,
3、变量或数组通过调用自定义函数,达到评分的效果
4、给出得分情况
问题是:
2~4过程如何实现
Private Sub 增加节点__Click()
'Add a node using tvwChild
Dim oNodex As Node
Dim skey As String
Dim iIndex As Integer
On Error GoTo myerr 'if the treeview does not have a node selected
' the next line of code will return an error number 91
iIndex = TreeView1.SelectedItem.Index 'Check to see if a Node is selected
Set oNodex = TreeView1.Nodes.Add(iIndex, tvwChild, skey, Combo1.Text, 1, 2)
oNodex.EnsureVisible 'make sure the child node is visible
Exit Sub
myerr:
'Display a messge telling the user to select a node
MsgBox ("You must select a Node to do an Add Child" & vbCrLf _
& "If the TreeView is empty us Add Last to create the first node")
Exit Sub
End Sub
Private Sub 删除 _Click()
'Remove the selected Node
Dim iIndex As Integer
On Error GoTo myerr 'if the treeview does not have a node selected
' the next line of code will return an error number 91
iIndex = TreeView1.SelectedItem.Index 'Check to see if a Node is selected
TreeView1.Nodes.Remove iIndex 'Removes the Node and any children it has
Exit Sub
myerr:
'Display a messge telling the user to select a node
MsgBox ("You must select a Node to do a Remove" & vbCrLf _
& "If the TreeView is empty us Add Last to create the first node")
Exit Sub
End Sub
Private Sub Form_Load()
Dim cn As New Connection, rs As New Recordset
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\pp.mdb"
rs.Open "Select * From 源码", cn
If Not rs.BOF And Not rs.EOF Then
rs.MoveFirst
Do While Not rs.EOF
Combo1.AddItem rs("KEY")
rs.MoveNext
Loop
End If
rs.Close
Set rs = Nothing
TreeView1.LineStyle = tvwTreeLines '在兄弟节点和父节点之间显示线
TreeView1.ImageList = ImageList1 '链接图像列
TreeView1.Style = tvwTreelinesPlusMinusPictureText
'树状外观包含全部元素
Set nodx = TreeView1.Nodes.Add(, , "EXCEL1", "EXCEL1", 1)
Set nodx = TreeView1.Nodes.Add("EXCEL1", tvwChild, "child01", "题目1", 2)
Set nodx = TreeView1.Nodes.Add("child01", tvwChild, "child011", "评分1", 3)
Set nodx = TreeView1.Nodes.Add("child01", tvwChild, "child012", "评分2", 3)
Set nodx = TreeView1.Nodes.Add("child01", tvwChild, "child013", "评分3", 3)
Set nodx = TreeView1.Nodes.Add("child01", tvwChild, "child014", "评分4", 3)
Set nodx = TreeView1.Nodes.Add("EXCEL1", tvwChild, "child02", "题目2", 2)
Set nodx = TreeView1.Nodes.Add("child02", tvwChild, "child021", "评分1", 3)
Set nodx = TreeView1.Nodes.Add("child02", tvwChild, "child022", "评分2", 3)
Set nodx = TreeView1.Nodes.Add("child02", tvwChild, "child023", "评分3", 3)
Set nodx = TreeView1.Nodes.Add("EXCEL1", tvwChild, "child03", "题目3", 2)
Set nodx = TreeView1.Nodes.Add("child03", tvwChild, "child031", "评分1", 3)
Set nodx = TreeView1.Nodes.Add("child03", tvwChild, "child032", "评分2", 3)
Set nodx = TreeView1.Nodes.Add("child03", tvwChild, "child033", "评分3", 3)
Set nodx = TreeView1.Nodes.Add("EXCEL1", tvwChild, "child04", "题目4", 2)
Set nodx = TreeView1.Nodes.Add("child04", tvwChild, "child041", "评分1", 3)
Set nodx = TreeView1.Nodes.Add("child04", tvwChild, "child042", "评分2", 3)
Set nodx = TreeView1.Nodes.Add("child04", tvwChild, "child043", "评分3", 3)
Set nodx = TreeView1.Nodes.Add("EXCEL1", tvwChild, "child05", "题目5", 2)
Set nodx = TreeView1.Nodes.Add("child05", tvwChild, "child051", "评分1", 3)
Set nodx = TreeView1.Nodes.Add("child05", tvwChild, "child052", "评分2", 3)
Set nodx = TreeView1.Nodes.Add("child05", tvwChild, "child053", "评分3", 3)
Set nodx = TreeView1.Nodes.Add("EXCEL1", tvwChild, "child06", "题目6", 2)
Set nodx = TreeView1.Nodes.Add("child06", tvwChild, "child061", "评分1", 3)
Set nodx = TreeView1.Nodes.Add("child06", tvwChild, "child062", "评分2", 3)
Set nodx = TreeView1.Nodes.Add("child06", tvwChild, "child063", "评分3", 3)
Set nodx = TreeView1.Nodes.Add("EXCEL1", tvwChild, "child07", "题目7", 2)
Set nodx = TreeView1.Nodes.Add("child07", tvwChild, "child071", "评分1", 3)
Set nodx = TreeView1.Nodes.Add(, , "EXCEL2", "EXCEL2", 1)
CunZai = False
End Sub
[解决办法]
楼主的代码中还有这么多英文注释啊
[解决办法]
找到深度最大的那个结点,然后读取数据内容