473,854 Members | 1,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What do you do when ListView.Items. Clear() doesn't clear??

Situation :
FormX is mdi child form containing 2 ListViews
ListView1 contains a list of table names and 4 sub items with data about
each table.
ListView2 contains a list of the columns on each table and 11 sub items with
data about each column.

When a Row in ListView1 is selected the Data in ListVies2 is loaded to show
the correct data. Initially the first row in ListView1 is selected in FormX
load
..
However when using ListView2.Items .Clear() before loading a new set of data
or blank data awaiting entries the previous data is not cleared and the new
data is not loaded. I know the change is taking place because the row back
colour changes are taking place correctly.(No data means matching row
colours, data present means alternating row back colours)

Any thoughts anyone????

Bob
Nov 21 '05 #1
21 5241
Hi,

post some code

Ken
----------------
"StriderBob " <rw**@mdbatisis ps.freeserve.co .uk> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Situation :
FormX is mdi child form containing 2 ListViews
ListView1 contains a list of table names and 4 sub items with data about
each table.
ListView2 contains a list of the columns on each table and 11 sub items with
data about each column.

When a Row in ListView1 is selected the Data in ListVies2 is loaded to show
the correct data. Initially the first row in ListView1 is selected in FormX
load
..
However when using ListView2.Items .Clear() before loading a new set of data
or blank data awaiting entries the previous data is not cleared and the new
data is not loaded. I know the change is taking place because the row back
colour changes are taking place correctly.(No data means matching row
colours, data present means alternating row back colours)

Any thoughts anyone????

Bob

Nov 21 '05 #2
REFERENCE Request for code by Ken :
The following is a slightly reduced copy of the code in use, There are more SubItems and in number more tables and columns.
However assuming I have reconstructed the example without typos this is the key code and method in use.

There is an assumption that an Array(layer, Row, Column) exists where layer 0 column 1 contains the table names and layer 0 columns 1 to 10 contain the column names. The table data is in layers 1 > n under column 0 while the column data is under the column name in layers 1 to n.
Private Sub ItemT0 As New ListViewItem("1 ", 0)
~
PrivateSub ItemT49 As New ListViewItem("5 0", 49)

Private Sub ItemC0 As New ListViewItem("1 ", 0)
~
Private Sub ItemC9 As New ListViewItem("1 0", 9)

WINDOWS FORM DESIGNER GENERATED CODE

Private Sub Form1_Load (etc)
LoadListViewIte msArray()
ListViewTables. Items.Clear()
ShowTablesInLis tView()
ListViewTables. Items(tblPosn). Selected = True
ListViewColumns .Items.Clear()
ShowColumnsInLi stView()
End Sub
Private Sub LoadListViewIte msArray()
ItemsT(0) = ItemsT0
~
ItemsT(49) = ItemsT49

ItemsC(0) = ItemsC0
~
ItemsC(9) = ItemsC9
End Sub
Private Sub ShowTablesInLis tView()
Dim h, i, As Integer
Dim str, str1, str2, str3 As String

ListViewTables. BeginUpdate()
For h = 0 to 49
str = Array(0, h, 0)
If str <> "No Entry" Then
str1 = Array(1, h, 0)
str2 = Array(2, h, 0)
str3 = Array(3, h, 0)
If str1 = "No Entry" Then str1 = ""
If str2 = "No Entry" Then str2 = ""
If str3 = "No Entry" Then str2 = ""
ItemsT(h).SubIt ems.Add(str1)
ItemsT(h).SubIt ems.Add(str2)
ItemsT(h).SubIt ems.Add(str3)
ListViewTables. Items.Add(Items T(h))
If h Mod 2 = 0 Then
ItemsT(h).BackC olor = Color.FloralWhi te
Else
ItemsT(h).BackC olor = Color.Moccasin
End If
ElseIf str = "No Entry" Then
ItemsT(h).SubIt ems.Add("")
ItemsT(h).SubIt ems.Add("")
ItemsT(h).SubIt ems.Add("")
ListViewTables. Items.Add(Items T(h))
ItemsT(h).BackC olor = Color.Moccasin
End If
Next
ListViewTables. EndUpdate()
End Sub
Private Sub ListViewTables_ KeyDown(etc)
If e.KeyCode = KeysDown Then
If tblPosn < 49 Then
ListViewTables. Items(tblPosn). Selected = False
tblPosn = tblPosn + 1
ListViewTables. Items(tblPosn). Selected = True
ListViewColumns .Items.Clear()
ShowColumnsInLi stView()
End If
ElseIf e.KeyCode = Keys.Up Then
If tblPosn > 0 Then
ListViewTables. Items(tblPosn). Selected = False
tblPosn = tblPosn - 1
ListViewTables. Items(tblPosn). Selected = True
ListViewColumns .Items.Clear()
ShowColumnsInLi stView()
End If
End If
End Sub
Private Sub ShowColumnsInLi stView()
Dim h, i, As Integer
Dim str, str1, str2, str3 As String

ListViewColumns .BeginUpdate()
For i = 1 to 10
str = Array(0, tblPosn, i)
If str <> "No Entry" Then
str1 = Array(1, tblPosn, i)
str2 = Array(2, tblPosn, i)
str3 = Array(3, tblPosn, 1)
If str1 = "No Entry" Then str1 = ""
If str2 = "No Entry" Then str2 = ""
If str3 = "No Entry" Then str2 = ""
ItemsC(i).SubIt ems.Add(str1)
ItemsC(i).SubIt ems.Add(str2)
ItemsC(i).SubIt ems.Add(str3)
ListViewColumns .Items.Add(Item sC(i))
If i Mod 2 = 0 Then
ItemsC(i).BackC olor = Color.FloralWhi te
Else
ItemsC(i).BackC olor = Color.Moccasin
End If
ElseIf str = "No Entry" Then
ItemsC(i).SubIt ems.Add("")
ItemsC(i).SubIt ems.Add("")
ItemsC(i).SubIt ems.Add("")
ListViewColumns .Items.Add(Item sC(i))
ItemsC(i).BackC olor = Color.Moccasin
End If
Next
ListViewColumns .EndUpdate()
End Sub

E & O.E

Bob
Nov 21 '05 #3
Bob, I found your code very difficult to setup and test, but I think I got the gist of it.

Looks like you just want to change ListViewColumns when you select something different in ListViewTables. With the added twist that you want ListViewTables first item preselected so that that ListViewColumns starts with some data showing.

Here is a VERY stripped down version. Create a new form and paste this in there and see if it gives you any ideas.
HTH,
Greg

Option Strict On

Public Class Form1
Inherits System.Windows. Forms.Form

Private loading As Boolean

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ListViewColumns As System.Windows. Forms.ListView
Friend WithEvents ListViewTables As System.Windows. Forms.ListView
Friend WithEvents ColumnHeader12 As System.Windows. Forms.ColumnHea der
Friend WithEvents ColumnHeader1 As System.Windows. Forms.ColumnHea der
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
Me.ListViewColu mns = New System.Windows. Forms.ListView
Me.ColumnHeader 12 = New System.Windows. Forms.ColumnHea der
Me.ListViewTabl es = New System.Windows. Forms.ListView
Me.ColumnHeader 1 = New System.Windows. Forms.ColumnHea der
Me.SuspendLayou t()
'
'ListViewColumn s
'
Me.ListViewColu mns.Columns.Add Range(New System.Windows. Forms.ColumnHea der() {Me.ColumnHeade r12})
Me.ListViewColu mns.Location = New System.Drawing. Point(16, 120)
Me.ListViewColu mns.MultiSelect = False
Me.ListViewColu mns.Name = "ListViewColumn s"
Me.ListViewColu mns.Size = New System.Drawing. Size(256, 97)
Me.ListViewColu mns.TabIndex = 0
Me.ListViewColu mns.View = System.Windows. Forms.View.Deta ils
'
'ColumnHeader12
'
Me.ColumnHeader 12.Text = "ColumnName "
Me.ColumnHeader 12.Width = 120
'
'ListViewTables
'
Me.ListViewTabl es.Columns.AddR ange(New System.Windows. Forms.ColumnHea der() {Me.ColumnHeade r1})
Me.ListViewTabl es.Location = New System.Drawing. Point(16, 8)
Me.ListViewTabl es.MultiSelect = False
Me.ListViewTabl es.Name = "ListViewTables "
Me.ListViewTabl es.Size = New System.Drawing. Size(256, 97)
Me.ListViewTabl es.TabIndex = 1
Me.ListViewTabl es.View = System.Windows. Forms.View.Deta ils
'
'ColumnHeader1
'
Me.ColumnHeader 1.Text = "TableName"
Me.ColumnHeader 1.Width = 120
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 266)
Me.Controls.Add (Me.ListViewTab les)
Me.Controls.Add (Me.ListViewCol umns)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

loading = True

ShowTablesInLis tView()

ListViewTables. Items(0).Select ed = True
ListViewTables. Select() ' this seems to be important

ShowColumnsInLi stView()

loading = False

End Sub

Private Sub ShowTablesInLis tView()
Dim h, i As Integer

Dim str, str1, str2, str3 As String

ListViewTables. BeginUpdate()
For h = 0 To 49

Dim lvi As New ListViewItem
lvi.Text = "Table" & h.ToString

If h Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhi te
Else
lvi.BackColor = Color.Moccasin
End If

ListViewTables. Items.Add(lvi)

Next
ListViewTables. EndUpdate()
End Sub

Private Sub ShowColumnsInLi stView()

If ListViewTables. SelectedIndices .Count = 0 Then Return

Dim h, i As Integer
Dim str, str1, str2, str3 As String

Dim tblPosn As Integer = ListViewTables. SelectedItems(0 ).Index

ListViewColumns .BeginUpdate()
ListViewColumns .Items.Clear()
For i = 1 To 10

Dim lvi As New ListViewItem
lvi.Text = "Table" & tblPosn & "-Column" & i.ToString

If i Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhi te
Else
lvi.BackColor = Color.Moccasin
End If

ListViewColumns .Items.Add(lvi)

Next
ListViewColumns .EndUpdate()
End Sub

Private Sub ListViewTables_ SelectedIndexCh anged(ByVal sender As Object, ByVal e As System.EventArg s) Handles ListViewTables. SelectedIndexCh anged
If loading = True Then Return

ShowColumnsInLi stView()
End Sub
End Class

"StriderBob " <rw**@mdbatisis ps.freeserve.co .uk> wrote in message news:uM******** ******@TK2MSFTN GP12.phx.gbl...
REFERENCE Request for code by Ken :
The following is a slightly reduced copy of the code in use, There are more SubItems and in number more tables and columns.
However assuming I have reconstructed the example without typos this is the key code and method in use.

There is an assumption that an Array(layer, Row, Column) exists where layer 0 column 1 contains the table names and layer 0 columns 1 to 10 contain the column names. The table data is in layers 1 > n under column 0 while the column data is under the column name in layers 1 to n.
Private Sub ItemT0 As New ListViewItem("1 ", 0)
~
PrivateSub ItemT49 As New ListViewItem("5 0", 49)

Private Sub ItemC0 As New ListViewItem("1 ", 0)
~
Private Sub ItemC9 As New ListViewItem("1 0", 9)

WINDOWS FORM DESIGNER GENERATED CODE

Private Sub Form1_Load (etc)
LoadListViewIte msArray()
ListViewTables. Items.Clear()
ShowTablesInLis tView()
ListViewTables. Items(tblPosn). Selected = True
ListViewColumns .Items.Clear()
ShowColumnsInLi stView()
End Sub
Private Sub LoadListViewIte msArray()
ItemsT(0) = ItemsT0
~
ItemsT(49) = ItemsT49

ItemsC(0) = ItemsC0
~
ItemsC(9) = ItemsC9
End Sub
Private Sub ShowTablesInLis tView()
Dim h, i, As Integer
Dim str, str1, str2, str3 As String

ListViewTables. BeginUpdate()
For h = 0 to 49
str = Array(0, h, 0)
If str <> "No Entry" Then
str1 = Array(1, h, 0)
str2 = Array(2, h, 0)
str3 = Array(3, h, 0)
If str1 = "No Entry" Then str1 = ""
If str2 = "No Entry" Then str2 = ""
If str3 = "No Entry" Then str2 = ""
ItemsT(h).SubIt ems.Add(str1)
ItemsT(h).SubIt ems.Add(str2)
ItemsT(h).SubIt ems.Add(str3)
ListViewTables. Items.Add(Items T(h))
If h Mod 2 = 0 Then
ItemsT(h).BackC olor = Color.FloralWhi te
Else
ItemsT(h).BackC olor = Color.Moccasin
End If
ElseIf str = "No Entry" Then
ItemsT(h).SubIt ems.Add("")
ItemsT(h).SubIt ems.Add("")
ItemsT(h).SubIt ems.Add("")
ListViewTables. Items.Add(Items T(h))
ItemsT(h).BackC olor = Color.Moccasin
End If
Next
ListViewTables. EndUpdate()
End Sub
Private Sub ListViewTables_ KeyDown(etc)
If e.KeyCode = KeysDown Then
If tblPosn < 49 Then
ListViewTables. Items(tblPosn). Selected = False
tblPosn = tblPosn + 1
ListViewTables. Items(tblPosn). Selected = True
ListViewColumns .Items.Clear()
ShowColumnsInLi stView()
End If
ElseIf e.KeyCode = Keys.Up Then
If tblPosn > 0 Then
ListViewTables. Items(tblPosn). Selected = False
tblPosn = tblPosn - 1
ListViewTables. Items(tblPosn). Selected = True
ListViewColumns .Items.Clear()
ShowColumnsInLi stView()
End If
End If
End Sub
Private Sub ShowColumnsInLi stView()
Dim h, i, As Integer
Dim str, str1, str2, str3 As String

ListViewColumns .BeginUpdate()
For i = 1 to 10
str = Array(0, tblPosn, i)
If str <> "No Entry" Then
str1 = Array(1, tblPosn, i)
str2 = Array(2, tblPosn, i)
str3 = Array(3, tblPosn, 1)
If str1 = "No Entry" Then str1 = ""
If str2 = "No Entry" Then str2 = ""
If str3 = "No Entry" Then str2 = ""
ItemsC(i).SubIt ems.Add(str1)
ItemsC(i).SubIt ems.Add(str2)
ItemsC(i).SubIt ems.Add(str3)
ListViewColumns .Items.Add(Item sC(i))
If i Mod 2 = 0 Then
ItemsC(i).BackC olor = Color.FloralWhi te
Else
ItemsC(i).BackC olor = Color.Moccasin
End If
ElseIf str = "No Entry" Then
ItemsC(i).SubIt ems.Add("")
ItemsC(i).SubIt ems.Add("")
ItemsC(i).SubIt ems.Add("")
ListViewColumns .Items.Add(Item sC(i))
ItemsC(i).BackC olor = Color.Moccasin
End If
Next
ListViewColumns .EndUpdate()
End Sub

E & O.E

Bob
Nov 21 '05 #4
Thanks Greg, give me a while to examine the concepts shown here, rebuild the main program and see what happens.

Bob

"Greg Burns" <greg_burns@DON T_SPAM_ME_hotma il.com> wrote in message news:eo******** ******@TK2MSFTN GP11.phx.gbl...
Bob, I found your code very difficult to setup and test, but I think I got the gist of it.

Looks like you just want to change ListViewColumns when you select something different in ListViewTables. With the added twist that you want ListViewTables first item preselected so that that ListViewColumns starts with some data showing.

Here is a VERY stripped down version. Create a new form and paste this in there and see if it gives you any ideas.
HTH,
Greg

Option Strict On

Public Class Form1
Inherits System.Windows. Forms.Form

Private loading As Boolean

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ListViewColumns As System.Windows. Forms.ListView
Friend WithEvents ListViewTables As System.Windows. Forms.ListView
Friend WithEvents ColumnHeader12 As System.Windows. Forms.ColumnHea der
Friend WithEvents ColumnHeader1 As System.Windows. Forms.ColumnHea der
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
Me.ListViewColu mns = New System.Windows. Forms.ListView
Me.ColumnHeader 12 = New System.Windows. Forms.ColumnHea der
Me.ListViewTabl es = New System.Windows. Forms.ListView
Me.ColumnHeader 1 = New System.Windows. Forms.ColumnHea der
Me.SuspendLayou t()
'
'ListViewColumn s
'
Me.ListViewColu mns.Columns.Add Range(New System.Windows. Forms.ColumnHea der() {Me.ColumnHeade r12})
Me.ListViewColu mns.Location = New System.Drawing. Point(16, 120)
Me.ListViewColu mns.MultiSelect = False
Me.ListViewColu mns.Name = "ListViewColumn s"
Me.ListViewColu mns.Size = New System.Drawing. Size(256, 97)
Me.ListViewColu mns.TabIndex = 0
Me.ListViewColu mns.View = System.Windows. Forms.View.Deta ils
'
'ColumnHeader12
'
Me.ColumnHeader 12.Text = "ColumnName "
Me.ColumnHeader 12.Width = 120
'
'ListViewTables
'
Me.ListViewTabl es.Columns.AddR ange(New System.Windows. Forms.ColumnHea der() {Me.ColumnHeade r1})
Me.ListViewTabl es.Location = New System.Drawing. Point(16, 8)
Me.ListViewTabl es.MultiSelect = False
Me.ListViewTabl es.Name = "ListViewTables "
Me.ListViewTabl es.Size = New System.Drawing. Size(256, 97)
Me.ListViewTabl es.TabIndex = 1
Me.ListViewTabl es.View = System.Windows. Forms.View.Deta ils
'
'ColumnHeader1
'
Me.ColumnHeader 1.Text = "TableName"
Me.ColumnHeader 1.Width = 120
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 266)
Me.Controls.Add (Me.ListViewTab les)
Me.Controls.Add (Me.ListViewCol umns)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

loading = True

ShowTablesInLis tView()

ListViewTables. Items(0).Select ed = True
ListViewTables. Select() ' this seems to be important

ShowColumnsInLi stView()

loading = False

End Sub

Private Sub ShowTablesInLis tView()
Dim h, i As Integer

Dim str, str1, str2, str3 As String

ListViewTables. BeginUpdate()
For h = 0 To 49

Dim lvi As New ListViewItem
lvi.Text = "Table" & h.ToString

If h Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhi te
Else
lvi.BackColor = Color.Moccasin
End If

ListViewTables. Items.Add(lvi)

Next
ListViewTables. EndUpdate()
End Sub

Private Sub ShowColumnsInLi stView()

If ListViewTables. SelectedIndices .Count = 0 Then Return

Dim h, i As Integer
Dim str, str1, str2, str3 As String

Dim tblPosn As Integer = ListViewTables. SelectedItems(0 ).Index

ListViewColumns .BeginUpdate()
ListViewColumns .Items.Clear()
For i = 1 To 10

Dim lvi As New ListViewItem
lvi.Text = "Table" & tblPosn & "-Column" & i.ToString

If i Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhi te
Else
lvi.BackColor = Color.Moccasin
End If

ListViewColumns .Items.Add(lvi)

Next
ListViewColumns .EndUpdate()
End Sub

Private Sub ListViewTables_ SelectedIndexCh anged(ByVal sender As Object, ByVal e As System.EventArg s) Handles ListViewTables. SelectedIndexCh anged
If loading = True Then Return

ShowColumnsInLi stView()
End Sub
End Class

"StriderBob " <rw**@mdbatisis ps.freeserve.co .uk> wrote in message news:uM******** ******@TK2MSFTN GP12.phx.gbl...
REFERENCE Request for code by Ken :
The following is a slightly reduced copy of the code in use, There are more SubItems and in number more tables and columns.
However assuming I have reconstructed the example without typos this is the key code and method in use.

There is an assumption that an Array(layer, Row, Column) exists where layer 0 column 1 contains the table names and layer 0 columns 1 to 10 contain the column names. The table data is in layers 1 > n under column 0 while the column data is under the column name in layers 1 to n.
Private Sub ItemT0 As New ListViewItem("1 ", 0)
~
PrivateSub ItemT49 As New ListViewItem("5 0", 49)

Private Sub ItemC0 As New ListViewItem("1 ", 0)
~
Private Sub ItemC9 As New ListViewItem("1 0", 9)

WINDOWS FORM DESIGNER GENERATED CODE

Private Sub Form1_Load (etc)
LoadListViewIte msArray()
ListViewTables. Items.Clear()
ShowTablesInLis tView()
ListViewTables. Items(tblPosn). Selected = True
ListViewColumns .Items.Clear()
ShowColumnsInLi stView()
End Sub
Private Sub LoadListViewIte msArray()
ItemsT(0) = ItemsT0
~
ItemsT(49) = ItemsT49

ItemsC(0) = ItemsC0
~
ItemsC(9) = ItemsC9
End Sub
Private Sub ShowTablesInLis tView()
Dim h, i, As Integer
Dim str, str1, str2, str3 As String

ListViewTables. BeginUpdate()
For h = 0 to 49
str = Array(0, h, 0)
If str <> "No Entry" Then
str1 = Array(1, h, 0)
str2 = Array(2, h, 0)
str3 = Array(3, h, 0)
If str1 = "No Entry" Then str1 = ""
If str2 = "No Entry" Then str2 = ""
If str3 = "No Entry" Then str2 = ""
ItemsT(h).SubIt ems.Add(str1)
ItemsT(h).SubIt ems.Add(str2)
ItemsT(h).SubIt ems.Add(str3)
ListViewTables. Items.Add(Items T(h))
If h Mod 2 = 0 Then
ItemsT(h).BackC olor = Color.FloralWhi te
Else
ItemsT(h).BackC olor = Color.Moccasin
End If
ElseIf str = "No Entry" Then
ItemsT(h).SubIt ems.Add("")
ItemsT(h).SubIt ems.Add("")
ItemsT(h).SubIt ems.Add("")
ListViewTables. Items.Add(Items T(h))
ItemsT(h).BackC olor = Color.Moccasin
End If
Next
ListViewTables. EndUpdate()
End Sub
Private Sub ListViewTables_ KeyDown(etc)
If e.KeyCode = KeysDown Then
If tblPosn < 49 Then
ListViewTables. Items(tblPosn). Selected = False
tblPosn = tblPosn + 1
ListViewTables. Items(tblPosn). Selected = True
ListViewColumns .Items.Clear()
ShowColumnsInLi stView()
End If
ElseIf e.KeyCode = Keys.Up Then
If tblPosn > 0 Then
ListViewTables. Items(tblPosn). Selected = False
tblPosn = tblPosn - 1
ListViewTables. Items(tblPosn). Selected = True
ListViewColumns .Items.Clear()
ShowColumnsInLi stView()
End If
End If
End Sub
Private Sub ShowColumnsInLi stView()
Dim h, i, As Integer
Dim str, str1, str2, str3 As String

ListViewColumns .BeginUpdate()
For i = 1 to 10
str = Array(0, tblPosn, i)
If str <> "No Entry" Then
str1 = Array(1, tblPosn, i)
str2 = Array(2, tblPosn, i)
str3 = Array(3, tblPosn, 1)
If str1 = "No Entry" Then str1 = ""
If str2 = "No Entry" Then str2 = ""
If str3 = "No Entry" Then str2 = ""
ItemsC(i).SubIt ems.Add(str1)
ItemsC(i).SubIt ems.Add(str2)
ItemsC(i).SubIt ems.Add(str3)
ListViewColumns .Items.Add(Item sC(i))
If i Mod 2 = 0 Then
ItemsC(i).BackC olor = Color.FloralWhi te
Else
ItemsC(i).BackC olor = Color.Moccasin
End If
ElseIf str = "No Entry" Then
ItemsC(i).SubIt ems.Add("")
ItemsC(i).SubIt ems.Add("")
ItemsC(i).SubIt ems.Add("")
ListViewColumns .Items.Add(Item sC(i))
ItemsC(i).BackC olor = Color.Moccasin
End If
Next
ListViewColumns .EndUpdate()
End Sub

E & O.E

Bob
Nov 21 '05 #5
Greg, I've copied and pasted your code and it does not work either. Is it possible I've got a computer problem or missed an update?
If you put the columns ListView to the right of the tables ListView and stretch them both down so that you can see to about table 30 and click on the tables mostly nothing happens. At random tables numbered above No 9 seem to change the columns ListView, mostly nothing happens and the highlighted table ceases to be highlighted.

Bob

Option Strict On

Public Class Form1
Inherits System.Windows. Forms.Form

Private loading As Boolean

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ListViewColumns As System.Windows. Forms.ListView
Friend WithEvents ListViewTables As System.Windows. Forms.ListView
Friend WithEvents ColumnHeader12 As System.Windows. Forms.ColumnHea der
Friend WithEvents ColumnHeader1 As System.Windows. Forms.ColumnHea der
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
Me.ListViewColu mns = New System.Windows. Forms.ListView
Me.ColumnHeader 12 = New System.Windows. Forms.ColumnHea der
Me.ListViewTabl es = New System.Windows. Forms.ListView
Me.ColumnHeader 1 = New System.Windows. Forms.ColumnHea der
Me.SuspendLayou t()
'
'ListViewColumn s
'
Me.ListViewColu mns.Columns.Add Range(New System.Windows. Forms.ColumnHea der() {Me.ColumnHeade r12})
Me.ListViewColu mns.Location = New System.Drawing. Point(16, 120)
Me.ListViewColu mns.MultiSelect = False
Me.ListViewColu mns.Name = "ListViewColumn s"
Me.ListViewColu mns.Size = New System.Drawing. Size(256, 97)
Me.ListViewColu mns.TabIndex = 0
Me.ListViewColu mns.View = System.Windows. Forms.View.Deta ils
'
'ColumnHeader12
'
Me.ColumnHeader 12.Text = "ColumnName "
Me.ColumnHeader 12.Width = 120
'
'ListViewTables
'
Me.ListViewTabl es.Columns.AddR ange(New System.Windows. Forms.ColumnHea der() {Me.ColumnHeade r1})
Me.ListViewTabl es.Location = New System.Drawing. Point(16, 8)
Me.ListViewTabl es.MultiSelect = False
Me.ListViewTabl es.Name = "ListViewTables "
Me.ListViewTabl es.Size = New System.Drawing. Size(256, 97)
Me.ListViewTabl es.TabIndex = 1
Me.ListViewTabl es.View = System.Windows. Forms.View.Deta ils
'
'ColumnHeader1
'
Me.ColumnHeader 1.Text = "TableName"
Me.ColumnHeader 1.Width = 120
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 266)
Me.Controls.Add (Me.ListViewTab les)
Me.Controls.Add (Me.ListViewCol umns)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

loading = True

ShowTablesInLis tView()

ListViewTables. Items(0).Select ed = True
ListViewTables. Select() ' this seems to be important

ShowColumnsInLi stView()

loading = False

End Sub

Private Sub ShowTablesInLis tView()
Dim h, i As Integer

Dim str, str1, str2, str3 As String

ListViewTables. BeginUpdate()
For h = 0 To 49

Dim lvi As New ListViewItem
lvi.Text = "Table" & h.ToString

If h Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhi te
Else
lvi.BackColor = Color.Moccasin
End If

ListViewTables. Items.Add(lvi)

Next
ListViewTables. EndUpdate()
End Sub

Private Sub ShowColumnsInLi stView()

If ListViewTables. SelectedIndices .Count = 0 Then Return

Dim h, i As Integer
Dim str, str1, str2, str3 As String

Dim tblPosn As Integer = ListViewTables. SelectedItems(0 ).Index

ListViewColumns .BeginUpdate()
ListViewColumns .Items.Clear()
For i = 1 To 10

Dim lvi As New ListViewItem
lvi.Text = "Table" & tblPosn & "-Column" & i.ToString

If i Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhi te
Else
lvi.BackColor = Color.Moccasin
End If

ListViewColumns .Items.Add(lvi)

Next
ListViewColumns .EndUpdate()
End Sub

Private Sub ListViewTables_ SelectedIndexCh anged(ByVal sender As Object, ByVal e As System.EventArg s) Handles ListViewTables. SelectedIndexCh anged
If loading = True Then Return

ShowColumnsInLi stView()
End Sub
End Class
Nov 21 '05 #6
Greg, I do not understand exactly why but after trying to incorporate your ideas with mine the following code seems to work.
It does include a small array sample. I hope that this code will be more understandable. Appologies for that.

Bob

PS I love your colour co-ordinated page here. If you ever get a spare month you can tell this dim wit how you do that !

Option Strict On
Public Class Form1
Inherits System.Windows. Forms.Form
Private loading As Boolean
Private Array(2, 19, 10) As String
Private tblPosn As Integer = 0
Private colPosn As Integer = 1
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ListViewColumns As System.Windows. Forms.ListView
Friend WithEvents ListViewTables As System.Windows. Forms.ListView
Friend WithEvents ColumnNo As System.Windows. Forms.ColumnHea der
Friend WithEvents TableNo As System.Windows. Forms.ColumnHea der
Friend WithEvents TableName As System.Windows. Forms.ColumnHea der
Friend WithEvents TableType As System.Windows. Forms.ColumnHea der
Friend WithEvents TableCharNo As System.Windows. Forms.ColumnHea der
Friend WithEvents ColumnType As System.Windows. Forms.ColumnHea der
Friend WithEvents ColumnName As System.Windows. Forms.ColumnHea der
Friend WithEvents ColumnCharNo As System.Windows. Forms.ColumnHea der
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
Me.ListViewColu mns = New System.Windows. Forms.ListView
Me.ColumnNo = New System.Windows. Forms.ColumnHea der
Me.ListViewTabl es = New System.Windows. Forms.ListView
Me.TableNo = New System.Windows. Forms.ColumnHea der
Me.TableName = New System.Windows. Forms.ColumnHea der
Me.TableType = New System.Windows. Forms.ColumnHea der
Me.TableCharNo = New System.Windows. Forms.ColumnHea der
Me.ColumnType = New System.Windows. Forms.ColumnHea der
Me.ColumnName = New System.Windows. Forms.ColumnHea der
Me.ColumnCharNo = New System.Windows. Forms.ColumnHea der
Me.SuspendLayou t()
'
'ListViewColumn s
'
Me.ListViewColu mns.Columns.Add Range(New System.Windows. Forms.ColumnHea der() {Me.ColumnNo, Me.ColumnName, Me.ColumnType, Me.ColumnCharNo })
Me.ListViewColu mns.FullRowSele ct = True
Me.ListViewColu mns.GridLines = True
Me.ListViewColu mns.Location = New System.Drawing. Point(444, 8)
Me.ListViewColu mns.MultiSelect = False
Me.ListViewColu mns.Name = "ListViewColumn s"
Me.ListViewColu mns.Size = New System.Drawing. Size(396, 304)
Me.ListViewColu mns.TabIndex = 0
Me.ListViewColu mns.View = System.Windows. Forms.View.Deta ils
'
'ColumnNo
'
Me.ColumnNo.Tex t = "No"
Me.ColumnNo.Wid th = 30
'
'ListViewTables
'
Me.ListViewTabl es.Columns.AddR ange(New System.Windows. Forms.ColumnHea der() {Me.TableNo, Me.TableName, Me.TableType, Me.TableCharNo} )
Me.ListViewTabl es.FullRowSelec t = True
Me.ListViewTabl es.GridLines = True
Me.ListViewTabl es.Location = New System.Drawing. Point(16, 8)
Me.ListViewTabl es.MultiSelect = False
Me.ListViewTabl es.Name = "ListViewTables "
Me.ListViewTabl es.Size = New System.Drawing. Size(394, 304)
Me.ListViewTabl es.TabIndex = 1
Me.ListViewTabl es.View = System.Windows. Forms.View.Deta ils
'
'TableNo
'
Me.TableNo.Text = "No"
Me.TableNo.Widt h = 30
'
'TableName
'
Me.TableName.Te xt = "Table"
Me.TableName.Wi dth = 120
'
'TableType
'
Me.TableType.Te xt = "Type"
Me.TableType.Wi dth = 120
'
'TableCharNo
'
Me.TableCharNo. Text = "Character No."
Me.TableCharNo. Width = 120
'
'ColumnType
'
Me.ColumnType.T ext = "Type"
Me.ColumnType.W idth = 120
'
'ColumnName
'
Me.ColumnName.T ext = "Column"
Me.ColumnName.W idth = 120
'
'ColumnCharNo
'
Me.ColumnCharNo .Text = "Character No"
Me.ColumnCharNo .Width = 120
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(856, 325)
Me.Controls.Add (Me.ListViewTab les)
Me.Controls.Add (Me.ListViewCol umns)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)
End Sub
#End Region

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
Dim g, h, i As Integer
OtherInitialize ()
For g = 0 To 2
For h = 0 To 19
For i = 0 To 10
Array(g, h, i) = "No Entry"
Next
Next
Next

Array(0, 0, 0) = "TableA"
Array(0, 1, 0) = "TableB"
Array(0, 2, 0) = "TableC"
Array(0, 3, 0) = "TableD"
Array(0, 4, 0) = "TableE"
Array(0, 5, 0) = "TableF"
Array(0, 6, 0) = "TableG"
Array(0, 7, 0) = "TableH"
Array(0, 8, 0) = "TableI"
Array(0, 9, 0) = "TableJ"
Array(0, 0, 1) = "TableA, Column1"
Array(0, 0, 2) = "TableA, Column2"
Array(0, 0, 3) = "TableA, Column3"
Array(0, 0, 4) = "TableA, Column4"
Array(0, 1, 1) = "TableB, Column1"
Array(0, 1, 2) = "TableB, Column2"
Array(0, 1, 3) = "TableB, Column3"
Array(0, 1, 4) = "TableB, Column4"
Array(0, 1, 5) = "TableB, Column5"
Array(0, 1, 6) = "TableB, Column6"
Array(0, 3, 1) = "TableD, Column1"
Array(0, 3, 2) = "TableD, Column2"
Array(0, 3, 3) = "TableD, Column3"
Array(1, 0, 0) = "TableType = W"
Array(1, 1, 0) = "TableType = W"
Array(1, 2, 0) = "TableType = W"
Array(1, 3, 0) = "TableType = X"
Array(1, 4, 0) = "TableType = X"
Array(1, 5, 0) = "TableType = Y"
Array(1, 6, 0) = "TableType = Y"
Array(1, 7, 0) = "TableType = Y"
Array(1, 8, 0) = "TableType = Z"
Array(1, 9, 0) = "TableType = Z"
Array(1, 0, 1) = "ColumnType = AA"
Array(1, 0, 2) = "ColumnType = AA"
Array(1, 0, 3) = "ColumnType = BB"
Array(1, 0, 4) = "ColumnType = BB"
Array(1, 1, 1) = "ColumnType = AA"
Array(1, 1, 2) = "ColumnType = AA"
Array(1, 1, 3) = "ColumnType = BB"
Array(1, 1, 4) = "ColumnType = BB"
Array(1, 1, 5) = "ColumnType = CC"
Array(1, 1, 6) = "ColumnType = CC"
Array(1, 3, 1) = "ColumnType = AA"
Array(1, 3, 2) = "ColumnType = BB"
Array(1, 3, 3) = "ColumnType = CC"
Array(2, 0, 0) = "TDataLengt h = 25"
Array(2, 1, 0) = "TDataLengt h = 25"
Array(2, 2, 0) = "TDataLengt h = 30"
Array(2, 3, 0) = "TDataLengt h = 30"
Array(2, 4, 0) = "TDataLengt h = 256"
Array(2, 5, 0) = "TDataLengt h = 256"
Array(2, 6, 0) = "TDataLengt h = 512"
Array(2, 7, 0) = "TDataLengt h = 512"
Array(2, 8, 0) = "TDataLengt h = 1024"
Array(2, 9, 0) = "TDataLengt h = 1024"
Array(2, 0, 1) = "CDataLengt h = 25"
Array(2, 0, 2) = "CDataLengt h = 25"
Array(2, 0, 3) = "CDataLengt h = 30"
Array(2, 0, 4) = "CDataLengt h = 30"
Array(2, 1, 1) = "CDataLengt h = 25"
Array(2, 1, 2) = "CDataLengt h = 25"
Array(2, 1, 3) = "CDataLengt h = 30"
Array(2, 1, 4) = "CDataLengt h = 30"
Array(2, 1, 5) = "CDataLengt h = 256"
Array(2, 1, 6) = "CDataLengt h = 256"
Array(2, 3, 1) = "CDataLengt h = 25"
Array(2, 3, 2) = "CDataLengt h = 30"
Array(2, 3, 3) = "CDataLengt h = 256"
End Sub
Private Sub StartForm1()
loading = True
ShowTablesInLis tView()
ListViewTables. Items(0).Select ed = True
ListViewTables. Select() ' this seems to be important
ShowColumnsInLi stView()
loading = False
End Sub
Private Sub ShowTablesInLis tView()
Dim h, i As Integer
Dim str1, str2, str3 As String
ListViewTables. BeginUpdate()
ListViewTables. Items.Clear()
For h = 0 To 19
Dim lvi As New ListViewItem
lvi.Text = h.ToString
str1 = Array(0, h, 0)
If str1 = "No Entry" Then str1 = ""
str2 = Array(1, h, 0)
If str2 = "No Entry" Then str2 = ""
str3 = Array(2, h, 0)
If str3 = "No Entry" Then str3 = ""
lvi.SubItems.Ad d(str1)
lvi.SubItems.Ad d(str2)
lvi.SubItems.Ad d(str3)
ListViewTables. Items.Add(lvi)
If str1 <> "" Then
If h Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhi te
Else
lvi.BackColor = Color.Moccasin
End If
ElseIf str1 = "" Then
lvi.BackColor = System.Drawing. SystemColors.Wi ndow
End If
Next
ListViewTables. EndUpdate()
End Sub
Private Sub ShowColumnsInLi stView()
Dim h, i As Integer
Dim str1, str2, str3 As String
If ListViewTables. SelectedIndices .Count = 0 Then Return
Dim tblPosn As Integer = ListViewTables. SelectedItems(0 ).Index
ListViewColumns .BeginUpdate()
ListViewColumns .Items.Clear()
For i = 1 To 10
Dim lvi As New ListViewItem
lvi.Text = i.ToString
str1 = Array(0, tblPosn, i)
If str1 = "No Entry" Then str1 = ""
str2 = Array(1, tblPosn, i)
If str2 = "No Entry" Then str2 = ""
str3 = Array(2, tblPosn, i)
If str3 = "No Entry" Then str3 = ""
lvi.SubItems.Ad d(str1)
lvi.SubItems.Ad d(str2)
lvi.SubItems.Ad d(str3)
If str1 <> "" Then
If i Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhi te
Else
lvi.BackColor = Color.Moccasin
End If
ElseIf str1 = "" Then
lvi.BackColor = System.Drawing. SystemColors.Wi ndow
End If
ListViewColumns .Items.Add(lvi)
Next
ListViewColumns .EndUpdate()
End Sub
Private Sub ListViewTables_ SelectedIndexCh anged(ByVal sender As Object, ByVal e As System.EventArg s) Handles ListViewTables. SelectedIndexCh anged
If loading = True Then Return
ShowColumnsInLi stView()
End Sub
Private Sub ListViewTables_ KeyDown(ByVal sender As Object, ByVal e As System.Windows. Forms.KeyEventA rgs) Handles ListViewTables. KeyDown
If e.KeyCode = Keys.Down Then
If tblPosn < 19 Then
ListViewTables. Items(tblPosn). Selected = False
tblPosn = tblPosn + 1
ListViewTables. Items(tblPosn). Selected = True
ShowColumnsInLi stView()
End If
ElseIf e.KeyCode = Keys.Up Then
If tblPosn > 0 Then
ListViewTables. Items(tblPosn). Selected = False
tblPosn = tblPosn - 1
ListViewTables. Items(tblPosn). Selected = True
ShowColumnsInLi stView()
End If
End If
End Sub

#Region " ON CLOSE FORM OR PROGRAM "
Private Sub OtherInitialize ()
AddHandler Me.Closing, AddressOf Me.Form1_Cancel
End Sub
Protected Sub Form1_Cancel(By Val sender As Object, ByVal e As System.Componen tModel.CancelEv entArgs)
e.Cancel = False
End Sub
Protected Overrides Sub OnVisibleChange d(ByVal e As System.EventArg s)
If Me.Visible = True Then
StartForm1()
End If
End Sub
#End Region

End Class
Nov 21 '05 #7
Strange. I directly pasted this code into a brand new form, then arranged the listviews side by side and enlarged. I am not seeing anything strange on my machine. I assume you are using VS.NET 2003?

Greg
"StriderBob " <rw**@mdbatisis ps.freeserve.co .uk> wrote in message news:ur******** ******@TK2MSFTN GP12.phx.gbl...
Greg, I've copied and pasted your code and it does not work either. Is it possible I've got a computer problem or missed an update?
If you put the columns ListView to the right of the tables ListView and stretch them both down so that you can see to about table 30 and click on the tables mostly nothing happens. At random tables numbered above No 9 seem to change the columns ListView, mostly nothing happens and the highlighted table ceases to be highlighted.

Bob

Option Strict On

Public Class Form1
Inherits System.Windows. Forms.Form

Private loading As Boolean

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ListViewColumns As System.Windows. Forms.ListView
Friend WithEvents ListViewTables As System.Windows. Forms.ListView
Friend WithEvents ColumnHeader12 As System.Windows. Forms.ColumnHea der
Friend WithEvents ColumnHeader1 As System.Windows. Forms.ColumnHea der
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
Me.ListViewColu mns = New System.Windows. Forms.ListView
Me.ColumnHeader 12 = New System.Windows. Forms.ColumnHea der
Me.ListViewTabl es = New System.Windows. Forms.ListView
Me.ColumnHeader 1 = New System.Windows. Forms.ColumnHea der
Me.SuspendLayou t()
'
'ListViewColumn s
'
Me.ListViewColu mns.Columns.Add Range(New System.Windows. Forms.ColumnHea der() {Me.ColumnHeade r12})
Me.ListViewColu mns.Location = New System.Drawing. Point(16, 120)
Me.ListViewColu mns.MultiSelect = False
Me.ListViewColu mns.Name = "ListViewColumn s"
Me.ListViewColu mns.Size = New System.Drawing. Size(256, 97)
Me.ListViewColu mns.TabIndex = 0
Me.ListViewColu mns.View = System.Windows. Forms.View.Deta ils
'
'ColumnHeader12
'
Me.ColumnHeader 12.Text = "ColumnName "
Me.ColumnHeader 12.Width = 120
'
'ListViewTables
'
Me.ListViewTabl es.Columns.AddR ange(New System.Windows. Forms.ColumnHea der() {Me.ColumnHeade r1})
Me.ListViewTabl es.Location = New System.Drawing. Point(16, 8)
Me.ListViewTabl es.MultiSelect = False
Me.ListViewTabl es.Name = "ListViewTables "
Me.ListViewTabl es.Size = New System.Drawing. Size(256, 97)
Me.ListViewTabl es.TabIndex = 1
Me.ListViewTabl es.View = System.Windows. Forms.View.Deta ils
'
'ColumnHeader1
'
Me.ColumnHeader 1.Text = "TableName"
Me.ColumnHeader 1.Width = 120
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 266)
Me.Controls.Add (Me.ListViewTab les)
Me.Controls.Add (Me.ListViewCol umns)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

loading = True

ShowTablesInLis tView()

ListViewTables. Items(0).Select ed = True
ListViewTables. Select() ' this seems to be important

ShowColumnsInLi stView()

loading = False

End Sub

Private Sub ShowTablesInLis tView()
Dim h, i As Integer

Dim str, str1, str2, str3 As String

ListViewTables. BeginUpdate()
For h = 0 To 49

Dim lvi As New ListViewItem
lvi.Text = "Table" & h.ToString

If h Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhi te
Else
lvi.BackColor = Color.Moccasin
End If

ListViewTables. Items.Add(lvi)

Next
ListViewTables. EndUpdate()
End Sub

Private Sub ShowColumnsInLi stView()

If ListViewTables. SelectedIndices .Count = 0 Then Return

Dim h, i As Integer
Dim str, str1, str2, str3 As String

Dim tblPosn As Integer = ListViewTables. SelectedItems(0 ).Index

ListViewColumns .BeginUpdate()
ListViewColumns .Items.Clear()
For i = 1 To 10

Dim lvi As New ListViewItem
lvi.Text = "Table" & tblPosn & "-Column" & i.ToString

If i Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhi te
Else
lvi.BackColor = Color.Moccasin
End If

ListViewColumns .Items.Add(lvi)

Next
ListViewColumns .EndUpdate()
End Sub

Private Sub ListViewTables_ SelectedIndexCh anged(ByVal sender As Object, ByVal e As System.EventArg s) Handles ListViewTables. SelectedIndexCh anged
If loading = True Then Return

ShowColumnsInLi stView()
End Sub
End Class
Nov 21 '05 #8
Why would no items be selected?

ShowColumnsInLi stView is called in your SelectedIndexCh anged event. That only gets called after something gets selected (or unselected).

Also we preselect an item before the first manual call to ShowColumnsInLi stView:
ListViewTables. Items(0).Select ed = True
ListViewTables. Select()
ShowColumnsInLi stView()

In fact the statement:
If ListViewTables. SelectedIndices .Count = 0 Then Return

directly before:
Dim tblPosn As Integer = ListViewTables. SelectedItems(0 ).Index

is our safetly net to prevent an exception if we somehow unselected an item (you would have to change MultiSelect=Tru e to have this happen).

Greg
"StriderBob " <rw**@mdbatisis ps.freeserve.co .uk> wrote in message news:uz******** ******@TK2MSFTN GP09.phx.gbl...
Correct, I'm tracking tblPosn, I copied "Dim tblPosn As Integer = ListViewTables. SelectedItems(0 ).Index" as another 'this seems to be important. It certainly made no sense to me. Surely "SelectedItems( 0).Index" means a reset of tblPosn to = 0 or = Nothing since no items are selected?

Bob

Nov 21 '05 #9
Post some code. :^)
"StriderBob " <rw**@mdbatisis ps.freeserve.co .uk> wrote in message news:OD******** ******@TK2MSFTN GP11.phx.gbl...
Strange is a good term. Like you I directly pasted it into a new form. Yes, I'm using VS Enterprise Architect 2003.
Some weeks ago I posted another question to which I have never received any answers whatever. It regarded mouse events and form.Show form Hide. Is it possible that I have some bug in my VS that stopped something happening on my machine and is the reason nobody replied to my queery, they could not reproduce the problem?

Very Simply in an mdi project I had buttons with changing Images that changed on mouse enter and mouse leave events like Web Buttons. However when the button was used to hide a form the button used to create the hide code and random other buttons locked in the hover image when the form was re-shown. I tried event handling etc but never solved the problm so ended up re-designing the whole project, some 30 forms, to appear as usual blocky windows buttons.

Any thoughts, Bob ?
"Greg Burns" <greg_burns@DON T_SPAM_ME_hotma il.com> wrote in message news:ej******** *****@TK2MSFTNG P12.phx.gbl...
Strange. I directly pasted this code into a brand new form, then arranged the listviews side by side and enlarged. I am not seeing anything strange on my machine. I assume you are using VS.NET 2003?

Greg
Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1858
by: newbie001 | last post by:
I have the following code in a listview control's initList function (called from form_load event). i can't understand why the listview box still appears blank with no columns or listview items. all help is appreciated. public void initList() { listView1.Enabled = true;
6
4666
by: VM | last post by:
How can I fill up a listview with text file contents? My listview has two columns and the first column fills up with a while loop: while (myString != null) { myString = sr.Readline(); listView1.Items.Add (myString); } Is there a way I can fill up the second column this easily? Thw way I'm currently doing it is using the subitems property to add it. Unfortunately,
9
6390
by: C# Learner | last post by:
Has anyone else noticed ListView's unbearable flickering? I have a project containing a list-view with the following: - View: Details - Columns: 5 The following code causes the list-view to flicker: private void TestListView() {
0
4488
by: Zac Maclean | last post by:
I have a working version of this in VB, tryign to translate everything over to C#. In the C# version this is filling the listview, the first couple columns are ok, but the last few are going screwy. In VB, it is working perfectly. The reason for move is speed. Takes a full 10 - 15 seconds to run this on VB, <5 in C#. I adapted this from
5
1356
by: twick10 | last post by:
Hi All, Is anybody aware or significant bugs in the Windows Forms ListView control?? I am having serious problems trying to switch from Large and small icon views to detail views. What looks fine in Large and small icon views shows up as lines on detail view and blank screen in File listing. If I do some brute force restating of columns (they were defined before) and imagelists I can get it to show up with double the number of...
2
6313
by: Mamatha | last post by:
Hi I have an application with listview.When i click on one button the data will be displayed like this in the listview: colA colB colC ----- ----- ------ nannacom.com 0 0 When i click on another button,i want to display like this
5
428
by: Alan T | last post by:
How do I define 3 coloumns display as: Name, Address, Phone ?
5
25975
by: John Devlon | last post by:
Hi, Does anyone know how to get a value of a second column of a selected item in Listview. I've create a listview and added this code Listview.Items.Clear() Listview.Columns.Clear() Listview.View = View.Details
3
14848
by: Mustaf Kazi | last post by:
Hi Can anyone tell me how to clear items from listview in vb.net 2003. I tried the code as Listview1.items.clear() but it doesn't work. is that any other method.
0
9901
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9751
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11025
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10682
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10758
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10371
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7082
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4159
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.