我正在使用GMAP库,我正在绘制不同的标记。我正在使用树视图控件,我在其中放置标记的名称,当我选中或取消选中名称时,相关的标记会显示或消失。
我也尝试使用checklistbox和listview控件来实现这一点,而treeview控件是我需要的,因为我需要有类别的标记,以及这些类别中的一些子项。这是代码:
在这里,我用我需要的元素填充树视图:
Private Sub addelementsToTreeview()
frmConfiguration_.TreeView1.Nodes.Add(StringResources.ControlCenterTree)
frmConfiguration_.TreeView1.Nodes.Add(StringResources.FOTree)
frmConfiguration_.TreeView1.Nodes.Add(StringResources.ArtilleryTree)
For Each value In foOverlay.Markers
frmConfiguration_.TreeView1.Nodes(1).Nodes.Add(value.ToolTipText)
Next
For Each value In artilleryOverlay.Markers
frmConfiguration_.TreeView1.Nodes(2).Nodes.Add(value.ToolTipText)
Next
frmConfiguration_.TreeView1.CheckBoxes = True
frmConfiguration_.TreeView1.Nodes(0).Checked = True
frmConfiguration_.TreeView1.Nodes(1).Checked = True
frmConfiguration_.TreeView1.Nodes(2).Checked = True
For i As Integer = 0 To frmConfiguration_.TreeView1.Nodes(1).GetNodeCount(False) - 1
frmConfiguration_.TreeView1.Nodes(1).Nodes(i).Checked = True
Next
For i As Integer = 0 To frmConfiguration_.TreeView1.Nodes(2).GetNodeCount(False) - 1
frmConfiguration_.TreeView1.Nodes(2).Nodes(i).Checked = True
Next
End Sub
我使用处理程序来控制itemCheck事件,放在Form_Load:
中AddHandler TreeView1.AfterCheck, AddressOf treeview1_ItemCheck
*我也尝试过使用TreeView1.BeforeCheck
,但效果相同。
这是我展示或隐藏我正在检查或取消选中的项目的时候:
Private Sub treeview1_ItemCheck(sender As Object, e As TreeViewEventArgs)
Dim counter As Integer
'Dim a = sender.treenode.parent
If sender.nodes.count > 0 Then
If e.Node.Text = StringResources.ControlCenterTree And e.Node.Checked = True Then
padre.controlCenterOverlay.IsVisibile = True
ElseIf e.Node.Text = StringResources.ControlCenterTree And e.Node.Checked = False Then
padre.controlCenterOverlay.IsVisibile = False
ElseIf e.Node.Text = StringResources.FOTree And e.Node.Checked = True Then
For i As Integer = 0 To TreeView1.Nodes(1).GetNodeCount(False) - 1
counter = i
TreeView1.Nodes(1).Nodes(counter).Checked = True
Dim marker As GMarkerGoogle = padre.foOverlay.Markers.FirstOrDefault(Function(o) o.ToolTipText = TreeView1.Nodes(1).Nodes(counter).Text)
marker.IsVisible = True
Next
ElseIf e.Node.Text = StringResources.FOTree And e.Node.Checked = False Then
For i As Integer = 0 To TreeView1.Nodes(1).GetNodeCount(False) - 1
counter = i
TreeView1.Nodes(1).Nodes(counter).Checked = False
Dim marker As GMarkerGoogle = padre.foOverlay.Markers.FirstOrDefault(Function(o) o.ToolTipText = TreeView1.Nodes(1).Nodes(counter).Text)
marker.IsVisible = False
Next
ElseIf e.Node.Text = StringResources.ArtilleryTree And e.Node.Checked = True Then
For i As Integer = 0 To TreeView1.Nodes(2).GetNodeCount(False) - 1
counter = i
TreeView1.Nodes(2).Nodes(counter).Checked = True
Dim marker As GMarkerGoogle = padre.artilleryOverlay.Markers.FirstOrDefault(Function(o) o.ToolTipText = TreeView1.Nodes(2).Nodes(counter).Text)
marker.IsVisible = True
Next
ElseIf e.Node.Text = StringResources.ArtilleryTree And e.Node.Checked = False Then
For i As Integer = 0 To TreeView1.Nodes(2).GetNodeCount(False) - 1
counter = i
TreeView1.Nodes(2).Nodes(counter).Checked = False
Dim marker As GMarkerGoogle = padre.foOverlay.Markers.FirstOrDefault(Function(o) o.ToolTipText = TreeView1.Nodes(2).Nodes(counter).Text)
marker.IsVisible = False
Next
Else
Dim marker As GMarkerGoogle = padre.foOverlay.Markers.FirstOrDefault(Function(o) o.ToolTipText = e.Node.Text)
If marker Is Nothing Then
marker = padre.artilleryOverlay.Markers.FirstOrDefault(Function(o) o.ToolTipText = e.Node.Text)
End If
If marker IsNot Nothing And e.Node.Checked = True Then
marker.IsVisible = True
ElseIf marker IsNot Nothing And e.Node.Checked = False Then
marker.IsVisible = False
End If
End If
End If
End Sub
一个问题和一个问题。首先是问题:
现在另一个问题:
- 关于代码,我正在使用if..elseif..else
结构。我也尝试过使用Select Case
结构,但最后一个对我来说并不值得,因为我有两个要求的条件,在Select Case
我只能放一个。我的意思是,这是不可能的:
select case e.node.text, e.node.checked
在结构的开头。所以这个结构对此无效。
有些人可以给我一些建议,以更有效的方式做到这一点吗?因为我无法想象如何做得更好。
谢谢!