您好网站成员, 我需要一些帮助,我已经使用此代码从三个表填充树视图使用现有的表链接:
Private Sub FillTREEVIEWTEXT()
Dim connGlobe As New SqlConnection("Data Source=ACCOUNTING\ACCOUNTING;Initial Catalog=DELLY;Integrated Security=SSPI;")
Dim pkp(0), pke(0) As DataColumn
Dim dtgroup, dtkol, dtmoin As New DataTable
Dim da As SqlDataAdapter
Dim i As Integer
Dim j As Integer
Dim k As Integer
'filling the datatables
Try
da = New SqlDataAdapter("SELECT stgrcode ,cast(stgrcode as varchar) +' / '+ cast(STGRNAME as varchar) as STGRNAME FROM tfw_accgrfixcode ORDER BY STGRCODE", connGlobe)
dtgroup.Clear()
da.Fill(dtgroup)
pke(0) = dtgroup.Columns("STGRCODE")
da = New SqlDataAdapter("SELECT stgrcode,stkolcode ,cast(stkolcode as varchar) +' / '+ cast(STKOLNAME as varchar) as STKOLNAME FROM tfw_acckolfixcode", connGlobe)
dtkol.Clear()
da.Fill(dtkol)
pke(0) = dtkol.Columns("STGRCODE")
da = New SqlDataAdapter("Select stgrcode,ukolcode ,cast(acckind as varchar) +' / '+ cast(UMOINNAME as varchar) as UMOINNAME from TFW_ACCMOFIXCODE", connGlobe)
dtmoin.Clear()
da.Fill(dtmoin)
pke(0) = dtmoin.Columns("STGRCODE")
connGlobe.Open()
'Creating the treeview
Dim tempNode As TreeNode
For i = 0 To dtgroup.Rows.Count - 1
TREEVIEW1.Nodes.Add(dtgroup.Rows(i).Item("STGRNAME"))
For j = 0 To dtkol.Rows.Count - 1
If dtgroup.Rows(i).Item("STGRCODE") = dtkol.Rows(j).Item("STGRCODE") Then
tempNode = TREEVIEW1.Nodes(i).Nodes.Add(dtkol.Rows(j).Item("STKOLNAME"))
For k = 0 To dtmoin.Rows.Count - 1
If dtkol.Rows(j).Item("STkolCODE") = dtmoin.Rows(k).Item("ukolCODE") Then
tempNode.Nodes.Add(dtmoin.Rows(k).Item("UMOINNAME"))
End If
Next
End If
Next
Next
connGlobe.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
到目前为止该应用程序运行良好,但现在我需要选择Node来通过Tree View更新表,我不知道为什么通过在文本框中选择任何父,子或孙的第一行值显示表格,换句话说,不显示文本框中所选节点的值。
这是我将win控件绑定到树视图的代码:
Private Sub TreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles TREEVIEW1.AfterSelect
Dim connGlobe As New SqlConnection("Data Source=ACCOUNTING\ACCOUNTING;Initial Catalog=DELLY;Integrated Security=SSPI;")
Dim dtContinent As New DataTable
Dim da As SqlDataAdapter
Try
da = New SqlDataAdapter("SELECT g.STGRCODE ,g.STGRNAME,G.ISFIX,K.ISFIX,K.MAHIAT,k.STkolCODE,k.STGRCODE,k.STKOLNAME,m.STMOINCODE,m.UMOINNAME,m.TAFKINDNAME01,m.TAFKINDNAME02,m.TAFKINDNAME03,m.TAFKINDNAME04,m.TAFKINDNAME05,m.TAFKINDNAME06,m.TAFKINDNAME07,TAFKINDNO,TAFKINDNO1,TAFKINDNO2,TAFKINDNO3,TAFKINDNO4,TAFKINDNO5,TAFKINDNO6,ISMNDTAF01,ISMNDTAF02,ISMNDTAF03,ISMNDTAF04,ISMNDTAF05,ISMNDTAF06,ISMNDTAF07 FROM tfw_accgrfixcode as g INNER JOIN tfw_acckolfixcode AS k
ON g.stgrcode = k.stgrcode
INNER JOIN TFW_ACCMOFIXCODE AS m
ON m.stgrcode = m.stgrcode", connGlobe)
da.Fill(dtContinent)
connGlobe.Open()
Dim commandBuilder As New SqlCommandBuilder(da)
bindingSource1.DataSource = dtContinent
da.Update(DirectCast(bindingSource1.DataSource, DataTable))
bindingSource1.Position = bindingSource1.IndexOf(e.Node.Text)
'If e.Node.Tag.ToString = "" Then Return
'TextBox1.Text = DirectCast(bindingSource1.Item(bindingSource1.Find("STGRNAME", e.Node.Tag)), DataRowView).Item("STGRCODE").ToString
TextBox1.DataBindings.Add("Text", bindingSource1, "STGRCODE")
TextBox2.DataBindings.Add("Text", bindingSource1, "STKOLCODE")
TextBox3.DataBindings.Add("Text", bindingSource1, "STMOINCODE")
TextBox4.DataBindings.Add("Text", bindingSource1, "STGRNAME")
TextBox5.DataBindings.Add("Text", bindingSource1, "STKOLNAME")
TextBox6.DataBindings.Add("Text", bindingSource1, "UMOINNAME")
RadioButton1.DataBindings.Add("CHECKED", bindingSource1, "ISFIX")
RadioButton2.DataBindings.Add("CHECKED", bindingSource1, "MAHIAT")
RadioButton3.DataBindings.Add("CHECKED", bindingSource1, "ISFIX")
RadioButton4.DataBindings.Add("CHECKED", bindingSource1, "MAHIAT")
ComboBox1.DataBindings.Add("Text", bindingSource1, "TAFKINDNAME01")
ComboBox2.DataBindings.Add("Text", bindingSource1, "TAFKINDNAME02")
ComboBox3.DataBindings.Add("Text", bindingSource1, "TAFKINDNAME03")
ComboBox4.DataBindings.Add("Text", bindingSource1, "TAFKINDNAME04")
ComboBox5.DataBindings.Add("Text", bindingSource1, "TAFKINDNAME05")
ComboBox6.DataBindings.Add("Text", bindingSource1, "TAFKINDNAME06")
ComboBox7.DataBindings.Add("Text", bindingSource1, "TAFKINDNAME07")
TextBox21.DataBindings.Add("Text", bindingSource1, "TAFKINDNO")
TextBox20.DataBindings.Add("Text", bindingSource1, "TAFKINDNO1")
TextBox19.DataBindings.Add("Text", bindingSource1, "TAFKINDNO2")
TextBox18.DataBindings.Add("Text", bindingSource1, "TAFKINDNO3")
TextBox17.DataBindings.Add("Text", bindingSource1, "TAFKINDNO4")
TextBox16.DataBindings.Add("Text", bindingSource1, "TAFKINDNO5")
TextBox15.DataBindings.Add("Text", bindingSource1, "TAFKINDNO6")
TextBox7.DataBindings.Add("Text", bindingSource1, "ISMNDTAF01")
TextBox8.DataBindings.Add("Text", bindingSource1, "ISMNDTAF02")
TextBox9.DataBindings.Add("Text", bindingSource1, "ISMNDTAF03")
TextBox10.DataBindings.Add("Text", bindingSource1, "ISMNDTAF04")
TextBox11.DataBindings.Add("Text", bindingSource1, "ISMNDTAF05")
TextBox12.DataBindings.Add("Text", bindingSource1, "ISMNDTAF06")
TextBox13.DataBindings.Add("Text", bindingSource1, "ISMNDTAF07")
TextBox1.DataBindings.Clear()
TextBox2.DataBindings.Clear()
TextBox3.DataBindings.Clear()
TextBox4.DataBindings.Clear()
TextBox5.DataBindings.Clear()
TextBox6.DataBindings.Clear()
RadioButton1.DataBindings.Clear()
RadioButton2.DataBindings.Clear()
RadioButton3.DataBindings.Clear()
RadioButton4.DataBindings.Clear()
ComboBox1.DataBindings.Clear()
ComboBox2.DataBindings.Clear()
ComboBox3.DataBindings.Clear()
ComboBox4.DataBindings.Clear()
ComboBox5.DataBindings.Clear()
ComboBox6.DataBindings.Clear()
ComboBox7.DataBindings.Clear()
TextBox21.DataBindings.Clear()
TextBox20.DataBindings.Clear()
TextBox19.DataBindings.Clear()
TextBox18.DataBindings.Clear()
TextBox17.DataBindings.Clear()
TextBox16.DataBindings.Clear()
TextBox15.DataBindings.Clear()
TextBox7.DataBindings.Clear()
TextBox8.DataBindings.Clear()
TextBox9.DataBindings.Clear()
TextBox10.DataBindings.Clear()
TextBox11.DataBindings.Clear()
TextBox12.DataBindings.Clear()
TextBox13.DataBindings.Clear()
connGlobe.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
任何人都可以帮助我吗?请 我向你致以最诚挚的问候。