来自XML的Treeview

时间:2016-07-08 09:16:59

标签: xml vb.net treeview

这是我的XML

<Template>
  <Criteria />
  <BatchTemplates>
    <All Checked="True">
      <Income>True</Income>
      <Expenditure>True</Expenditure>
      <DonationIncome>True</DonationIncome>
      <EventIncome>True</EventIncome>
      <ChequePayment>True</ChequePayment>
      <Journal>True</Journal>
      <GiftAidDonationIncome>True</GiftAidDonationIncome>
      <ConfirmedGiftAid>True</ConfirmedGiftAid>
      <Commitment>True</Commitment>
      <AccruedIncome>True</AccruedIncome>
    </All>
  </BatchTemplates>
</Template>

这是我用来填充

形式的树视图的代码
' to initialise
    rNode = tvBatchTemplates.Nodes.Add("All", "All")
    rNode.Tag = "All"
    rNode.Checked = True

    For Each BatchTemplate As objBatchTemplates In BatchTemplate_Collection
        pNode = rNode.Nodes.Add(BatchTemplate.Name)
        pNode.Tag = BatchTemplate.Id
        pNode.Checked = True
    Next

' to populate the tree view
    xmlNodeList = xmlDoc.SelectNodes("/Template/BatchTemplates/All")
    tvBatchTemplates.Nodes(0).Checked = xmlNodeList.Item(0).Attributes(0).Value
    If xmlNodeList.Count > 0 Then Call PopulateTreeViews(xmlNodeList.Item(0), tvBatchTemplates.Nodes(0))

Private Sub PopulateTreeViews(ByRef xmlNode as XMLNode, ByRef ctlTreeviewNode as TreeNode)

    For intIndex As Integer = 0 To ctlTreeViewNode.Nodes.Count - 1

        If (Replace(ctlTreeViewNode.Nodes(intIndex).Text, " ", "")) = xmlNode.SelectSingleNode(Replace(ctlTreeViewNode.Nodes(intIndex).Text, " ", "").Name Then _
            ctlTreeViewNode.Nodes(intIndex).Checked = xmlNode.SelectSingleNode(Replace(ctlTreeViewNode.Nodes(intIndex).Text, " ", "").InnerText
    Next

End Sub

我遇到的问题是,这段代码在树视图上添加了一组额外的节点,与已经存在的节点完全相同。as shown here

没有其他事件被解雇(我已经检查过)。

0 个答案:

没有答案