RoyLittle0
Active member
Hi,
I have a form that updates 12 ListViews on a click, all works fine they update all the way to the end 1 - 12, then, with all ListViews full ii click on the upper ListViews i loose the horizontal scroll function on the next Listviews, this unly seems to happen when they have updated.
All listviews are set to 3 columns at 200, 90, 2000
Any idea why??
I have a form that updates 12 ListViews on a click, all works fine they update all the way to the end 1 - 12, then, with all ListViews full ii click on the upper ListViews i loose the horizontal scroll function on the next Listviews, this unly seems to happen when they have updated.
All listviews are set to 3 columns at 200, 90, 2000
Any idea why??
VB.NET:
Option Strict On
Imports System.Xml
Imports System.IO
Public Class Form1
Dim xmlDoc As New XmlDocument()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strmReader As New StreamReader("C:\Users\Roy Littlewood\Documents\Visual Studio 2010\Projects\WindowsApplication2\WindowsApplication2\bin\Debug\IBS2000.xml", System.Text.Encoding.UTF8)
Dim xmlReader As XmlTextReader = New XmlTextReader(strmReader)
Me.AutoScroll = True
Me.VScroll = True
Me.HScroll = True
'read the file and load the first list view
xmlReader.WhitespaceHandling = WhitespaceHandling.None
xmlDoc.Load(xmlReader)
Dim strXMLPos As String = "//Root/Root1/Section1"
Dim xml_LV1List As XmlNodeList = xmlDoc.SelectNodes(strXMLPos)
For Each curNode As XmlNode In xml_LV1List
Dim LVI As New ListViewItem
With LVI
.Text = curNode.Attributes.ItemOf("Name").InnerText
.SubItems.Add(curNode.Attributes.ItemOf("id").InnerText)
.SubItems.Add(curNode.Attributes.ItemOf("Label").InnerText)
End With
ListView_1.Items.Add(LVI)
Next
'add each list view header
AddListViewHeader(Listview_1)
AddListViewHeader(ListView_2)
AddListViewHeader(Listview_3)
AddListViewHeader(Listview_4)
AddListViewHeader(Listview_5)
AddListViewHeader(Listview_6)
AddListViewHeader(Listview_7)
AddListViewHeader(Listview_8)
AddListViewHeader(Listview_9)
AddListViewHeader(Listview_10)
AddListViewHeader(Listview_11)
AddListViewHeader(Listview_12)
End Sub
'this add's the list view headers
Private Sub AddListViewHeader(ByVal LV As ListView)
Dim Headers() As ColumnHeader = {New ColumnHeader With {.Text = "Name", .Width = 200},
New ColumnHeader With {.Text = "ID", .Width = 90, .TextAlign = HorizontalAlignment.Center},
New ColumnHeader With {.Text = "Label", .Width = 2000}}
LV.Columns.Clear()
LV.Columns.AddRange(Headers)
End Sub
'see that we handle all the listview SelectedIndexChanged events here
Private Sub ListView_1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Listview_1.SelectedIndexChanged, ListView_2.SelectedIndexChanged, Listview_3.SelectedIndexChanged, Listview_4.SelectedIndexChanged, Listview_5.SelectedIndexChanged, Listview_6.SelectedIndexChanged, Listview_7.SelectedIndexChanged, Listview_8.SelectedIndexChanged, Listview_9.SelectedIndexChanged, Listview_10.SelectedIndexChanged, Listview_11.SelectedIndexChanged, Listview_12.SelectedIndexChanged
'cast the clicked list view to the listview type
Dim myListView As ListView = DirectCast(sender, ListView)
If myListView.SelectedItems.Count > 0 Then
Const MaxListViews As Integer = 12
Const ControlSelector As String = "ListView_"
'identify and save the node location here
Dim NodeLocation As Integer = CInt(myListView.Name.Substring(myListView.Name.LastIndexOf("_") + 1, (myListView.Name.Length - 1) - myListView.Name.LastIndexOf("_")))
'clear the other list views
For ctrlCount As Integer = NodeLocation + 1 To 12
Dim ControlToClear As ListView = DirectCast(Me.Controls(ControlSelector & ctrlCount), ListView)
ControlToClear.Items.Clear()
Next
If NodeLocation < MaxListViews Then
'set an object to the next control to be updated
Dim myNextControl As ListView = DirectCast(Me.Controls(ControlSelector & NodeLocation + 1), ListView)
Dim strXMLPos As String = "//Root"
'identify the selected ID of the element that has been clicked
Dim SelectedID As Integer = CInt(myListView.SelectedItems(0).SubItems(1).Text)
'create the string to read nodes from the file
For Counter As Integer = 1 To NodeLocation + 1
strXMLPos += "/Root" & Counter & "/Section" & Counter
Next
'get the node list at the specified location
Dim nodesToDisplay = (From MyNode In xmlDoc.SelectNodes(strXMLPos) Select MyNode, NodeID = CInt(DirectCast(MyNode, XmlNode).ParentNode.ParentNode.Attributes.ItemOf("id").InnerText) Where NodeID = SelectedID)
For Each curNode In nodesToDisplay
Dim myNode As XmlNode = DirectCast(curNode.MyNode, XmlNode)
Dim LVI As New ListViewItem
With LVI
.Text = myNode.Attributes.ItemOf("Name").InnerText
.SubItems.Add(myNode.Attributes.ItemOf("id").InnerText)
.SubItems.Add(myNode.Attributes.ItemOf("Label").InnerText)
End With
myNextControl.Items.Add(LVI)
Next
AddListViewHeader(myNextControl)
End If
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form4.Show()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form3.Show()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Form2.Show()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Close()
End Sub
End Class