求教:vb.net 2005中Form1的TreeView1控件显示的内容如何在form2的treeview2控件中显示
2005中Form1的TreeView1控件显示的内容如何在form2的treeview2控件中显示:补充说明:1、Form1的TreeView1控件显示的内容是通过外部xml文件调用显示出来的。
2、Form1的代码:
Imports System.Collections.Generic
Public Class Form1
Public Sub New()
InitializeComponent()
CreatTreeViewBind()
End Sub
Public Class WebTvs
Public Shared XmlPath As String = String.Empty
Private _tvname As String
Private _tvaddress As String
Private _tvkind As String
Private _tvremark As String
''' <summary>
''' 电视台名称
''' </summary>
Public Property TvName() As String
Get
Return _tvname
End Get
Set(ByVal value As String)
_tvname = value
End Set
End Property
''' <summary>
''' 电视台MMS地址
''' </summary>
Public Property TvAddress() As String
Get
Return _tvaddress
End Get
Set(ByVal value As String)
_tvaddress = value
End Set
End Property
''' <summary>
''' 电视台所属类别
''' </summary>
Public Property TvKind() As String
Get
Return _tvkind
End Get
Set(ByVal value As String)
_tvkind = value
End Set
End Property
''' <summary>
''' 电视台备注
''' </summary>
Public Property TvRemark() As String
Get
Return _tvremark
End Get
Set(ByVal value As String)
_tvremark = value
End Set
End Property
Public Sub New()
End Sub
''' <summary>
''' 构造函数
''' </summary>
''' <param name="tvname">电视台名称</param>
''' <param name="tvadd">电视台</param>
''' <param name="tvkind">电视台所属类别</param>
''' <param name="tvremark">电视台备注</param>
Public Sub New(ByVal tvname As String, ByVal tvadd As String, ByVal tvkind As String, ByVal tvremark As String)
Me._tvname = tvname
Me._tvaddress = tvadd
Me._tvkind = tvkind
Me._tvremark = tvremark
End Sub
Public Shared Function GetTvInfo() As List(Of WebTvs)
Dim webList As New List(Of WebTvs)()
Dim xlist As List(Of Xml.XmlNode) = XmlOperate.GetSecondNode(XmlPath)
For Each xd As Xml.XmlNode In xlist
If xd.Name <> "xml" Then
For Each xdd As Xml.XmlNode In xd.ChildNodes
Dim newTv As New WebTvs()
'获取子节点信息tv—info
newTv.TvKind = xdd.Name
For Each xddd As Xml.XmlNode In xdd.ChildNodes
Select Case xddd.Name
Case "tv_name"
newTv.TvName = xddd.InnerText
Exit Select
Case "tv_address"
newTv.TvAddress = xddd.InnerText
Exit Select
' case "tv_kind":
' newTv.TvKind = xddd.InnerText; break;
Case "tv_remark"
newTv.TvRemark = xddd.InnerText
Exit Select
Case Else
Exit Select
End Select
Next
webList.Add(newTv)
Next
End If
Next
Return webList
End Function
''' <summary>
''' 返回节目类别信息
''' </summary>
''' <returns></returns>
Public Shared Function GetTvKindInfo() As List(Of String)
Dim webList As New List(Of String)()
Dim xlist As List(Of Xml.XmlNode) = XmlOperate.GetSecondNode(XmlPath)
For Each xd As Xml.XmlNode In xlist
If xd.Name <> "xml" Then
For Each xdd As Xml.XmlNode In xd.ChildNodes
Dim flag As Boolean = True
'获取子节点信息tv—info
For Each i As String In webList
If i = xdd.Name Then
flag = False
Exit For
End If
Next
If flag Then
webList.Add(xdd.Name)
End If
Next
End If
Next
Return webList
End Function
End Class
Public Class XmlOperate
Public Shared Function GetSecondNode(ByVal xmlPath As String) As List(Of Xml.XmlNode)
Dim xlist As New List(Of Xml.XmlNode)()
Dim xdoc As New Xml.XmlDocument()
xdoc.Load(xmlPath)
Dim xdl As Xml.XmlNodeList = xdoc.ChildNodes
For Each xd As Xml.XmlNode In xdl
xlist.Add(xd)
Next
Return xlist
End Function
End Class
Private Sub treeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles treeView1.AfterSelect
If True Then
Dim tn As TreeNode = Me.treeView1.SelectedNode
If tn.Tag IsNot Nothing Then
Dim wt As WebTvs = DirectCast(tn.Tag, WebTvs)
Form1.WindowsMediaPlayer1.URL = wt.TvAddress
If wt.TvAddress IsNot Nothing Then
Timer1.Enabled = False
End If
End If
End If
End Sub
Private Sub CreatTreeViewBind()
If True Then
WebTvs.XmlPath = "TvList.xml"
Dim list As List(Of String) = WebTvs.GetTvKindInfo()
For Each ls As String In list
Dim tn As New TreeNode(ls)
Dim tvList As List(Of WebTvs) = WebTvs.GetTvInfo()
If True Then
For Each wt As WebTvs In tvList
Dim ts As New TreeNode()
If wt.TvKind = ls Then
ts.Text = wt.TvName
ts.Tag = wt
tn.Nodes.Add(ts)
End If
Next
End If
Me.treeView1.Nodes.Add(tn)
Next
End If
End Sub