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

S

StriderBob

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
 
K

Ken Tucker [MVP]

Hi,

post some code

Ken
----------------
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
 
S

StriderBob

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("50", 49)

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

WINDOWS FORM DESIGNER GENERATED CODE

Private Sub Form1_Load (etc)
LoadListViewItemsArray()
ListViewTables.Items.Clear()
ShowTablesInListView()
ListViewTables.Items(tblPosn).Selected = True
ListViewColumns.Items.Clear()
ShowColumnsInListView()
End Sub
Private Sub LoadListViewItemsArray()
ItemsT(0) = ItemsT0
~
ItemsT(49) = ItemsT49

ItemsC(0) = ItemsC0
~
ItemsC(9) = ItemsC9
End Sub
Private Sub ShowTablesInListView()
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).SubItems.Add(str1)
ItemsT(h).SubItems.Add(str2)
ItemsT(h).SubItems.Add(str3)
ListViewTables.Items.Add(ItemsT(h))
If h Mod 2 = 0 Then
ItemsT(h).BackColor = Color.FloralWhite
Else
ItemsT(h).BackColor = Color.Moccasin
End If
ElseIf str = "No Entry" Then
ItemsT(h).SubItems.Add("")
ItemsT(h).SubItems.Add("")
ItemsT(h).SubItems.Add("")
ListViewTables.Items.Add(ItemsT(h))
ItemsT(h).BackColor = 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()
ShowColumnsInListView()
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()
ShowColumnsInListView()
End If
End If
End Sub
Private Sub ShowColumnsInListView()
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).SubItems.Add(str1)
ItemsC(i).SubItems.Add(str2)
ItemsC(i).SubItems.Add(str3)
ListViewColumns.Items.Add(ItemsC(i))
If i Mod 2 = 0 Then
ItemsC(i).BackColor = Color.FloralWhite
Else
ItemsC(i).BackColor = Color.Moccasin
End If
ElseIf str = "No Entry" Then
ItemsC(i).SubItems.Add("")
ItemsC(i).SubItems.Add("")
ItemsC(i).SubItems.Add("")
ListViewColumns.Items.Add(ItemsC(i))
ItemsC(i).BackColor = Color.Moccasin
End If
Next
ListViewColumns.EndUpdate()
End Sub

E & O.E

Bob
 
G

Greg Burns

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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.ColumnHeader
Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ListViewColumns = New System.Windows.Forms.ListView
Me.ColumnHeader12 = New System.Windows.Forms.ColumnHeader
Me.ListViewTables = New System.Windows.Forms.ListView
Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
Me.SuspendLayout()
'
'ListViewColumns
'
Me.ListViewColumns.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader12})
Me.ListViewColumns.Location = New System.Drawing.Point(16, 120)
Me.ListViewColumns.MultiSelect = False
Me.ListViewColumns.Name = "ListViewColumns"
Me.ListViewColumns.Size = New System.Drawing.Size(256, 97)
Me.ListViewColumns.TabIndex = 0
Me.ListViewColumns.View = System.Windows.Forms.View.Details
'
'ColumnHeader12
'
Me.ColumnHeader12.Text = "ColumnName"
Me.ColumnHeader12.Width = 120
'
'ListViewTables
'
Me.ListViewTables.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1})
Me.ListViewTables.Location = New System.Drawing.Point(16, 8)
Me.ListViewTables.MultiSelect = False
Me.ListViewTables.Name = "ListViewTables"
Me.ListViewTables.Size = New System.Drawing.Size(256, 97)
Me.ListViewTables.TabIndex = 1
Me.ListViewTables.View = System.Windows.Forms.View.Details
'
'ColumnHeader1
'
Me.ColumnHeader1.Text = "TableName"
Me.ColumnHeader1.Width = 120
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.ListViewTables)
Me.Controls.Add(Me.ListViewColumns)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

loading = True

ShowTablesInListView()

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

ShowColumnsInListView()

loading = False

End Sub

Private Sub ShowTablesInListView()
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.FloralWhite
Else
lvi.BackColor = Color.Moccasin
End If

ListViewTables.Items.Add(lvi)

Next
ListViewTables.EndUpdate()
End Sub

Private Sub ShowColumnsInListView()

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.FloralWhite
Else
lvi.BackColor = Color.Moccasin
End If

ListViewColumns.Items.Add(lvi)

Next
ListViewColumns.EndUpdate()
End Sub

Private Sub ListViewTables_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewTables.SelectedIndexChanged
If loading = True Then Return

ShowColumnsInListView()
End Sub
End Class

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("50", 49)

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

WINDOWS FORM DESIGNER GENERATED CODE

Private Sub Form1_Load (etc)
LoadListViewItemsArray()
ListViewTables.Items.Clear()
ShowTablesInListView()
ListViewTables.Items(tblPosn).Selected = True
ListViewColumns.Items.Clear()
ShowColumnsInListView()
End Sub
Private Sub LoadListViewItemsArray()
ItemsT(0) = ItemsT0
~
ItemsT(49) = ItemsT49

ItemsC(0) = ItemsC0
~
ItemsC(9) = ItemsC9
End Sub
Private Sub ShowTablesInListView()
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).SubItems.Add(str1)
ItemsT(h).SubItems.Add(str2)
ItemsT(h).SubItems.Add(str3)
ListViewTables.Items.Add(ItemsT(h))
If h Mod 2 = 0 Then
ItemsT(h).BackColor = Color.FloralWhite
Else
ItemsT(h).BackColor = Color.Moccasin
End If
ElseIf str = "No Entry" Then
ItemsT(h).SubItems.Add("")
ItemsT(h).SubItems.Add("")
ItemsT(h).SubItems.Add("")
ListViewTables.Items.Add(ItemsT(h))
ItemsT(h).BackColor = 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()
ShowColumnsInListView()
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()
ShowColumnsInListView()
End If
End If
End Sub
Private Sub ShowColumnsInListView()
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).SubItems.Add(str1)
ItemsC(i).SubItems.Add(str2)
ItemsC(i).SubItems.Add(str3)
ListViewColumns.Items.Add(ItemsC(i))
If i Mod 2 = 0 Then
ItemsC(i).BackColor = Color.FloralWhite
Else
ItemsC(i).BackColor = Color.Moccasin
End If
ElseIf str = "No Entry" Then
ItemsC(i).SubItems.Add("")
ItemsC(i).SubItems.Add("")
ItemsC(i).SubItems.Add("")
ListViewColumns.Items.Add(ItemsC(i))
ItemsC(i).BackColor = Color.Moccasin
End If
Next
ListViewColumns.EndUpdate()
End Sub

E & O.E

Bob
 
S

StriderBob

Thanks Greg, give me a while to examine the concepts shown here, rebuild the main program and see what happens.

Bob



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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.ColumnHeader
Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ListViewColumns = New System.Windows.Forms.ListView
Me.ColumnHeader12 = New System.Windows.Forms.ColumnHeader
Me.ListViewTables = New System.Windows.Forms.ListView
Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
Me.SuspendLayout()
'
'ListViewColumns
'
Me.ListViewColumns.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader12})
Me.ListViewColumns.Location = New System.Drawing.Point(16, 120)
Me.ListViewColumns.MultiSelect = False
Me.ListViewColumns.Name = "ListViewColumns"
Me.ListViewColumns.Size = New System.Drawing.Size(256, 97)
Me.ListViewColumns.TabIndex = 0
Me.ListViewColumns.View = System.Windows.Forms.View.Details
'
'ColumnHeader12
'
Me.ColumnHeader12.Text = "ColumnName"
Me.ColumnHeader12.Width = 120
'
'ListViewTables
'
Me.ListViewTables.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1})
Me.ListViewTables.Location = New System.Drawing.Point(16, 8)
Me.ListViewTables.MultiSelect = False
Me.ListViewTables.Name = "ListViewTables"
Me.ListViewTables.Size = New System.Drawing.Size(256, 97)
Me.ListViewTables.TabIndex = 1
Me.ListViewTables.View = System.Windows.Forms.View.Details
'
'ColumnHeader1
'
Me.ColumnHeader1.Text = "TableName"
Me.ColumnHeader1.Width = 120
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.ListViewTables)
Me.Controls.Add(Me.ListViewColumns)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

loading = True

ShowTablesInListView()

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

ShowColumnsInListView()

loading = False

End Sub

Private Sub ShowTablesInListView()
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.FloralWhite
Else
lvi.BackColor = Color.Moccasin
End If

ListViewTables.Items.Add(lvi)

Next
ListViewTables.EndUpdate()
End Sub

Private Sub ShowColumnsInListView()

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.FloralWhite
Else
lvi.BackColor = Color.Moccasin
End If

ListViewColumns.Items.Add(lvi)

Next
ListViewColumns.EndUpdate()
End Sub

Private Sub ListViewTables_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewTables.SelectedIndexChanged
If loading = True Then Return

ShowColumnsInListView()
End Sub
End Class

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("50", 49)

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

WINDOWS FORM DESIGNER GENERATED CODE

Private Sub Form1_Load (etc)
LoadListViewItemsArray()
ListViewTables.Items.Clear()
ShowTablesInListView()
ListViewTables.Items(tblPosn).Selected = True
ListViewColumns.Items.Clear()
ShowColumnsInListView()
End Sub
Private Sub LoadListViewItemsArray()
ItemsT(0) = ItemsT0
~
ItemsT(49) = ItemsT49

ItemsC(0) = ItemsC0
~
ItemsC(9) = ItemsC9
End Sub
Private Sub ShowTablesInListView()
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).SubItems.Add(str1)
ItemsT(h).SubItems.Add(str2)
ItemsT(h).SubItems.Add(str3)
ListViewTables.Items.Add(ItemsT(h))
If h Mod 2 = 0 Then
ItemsT(h).BackColor = Color.FloralWhite
Else
ItemsT(h).BackColor = Color.Moccasin
End If
ElseIf str = "No Entry" Then
ItemsT(h).SubItems.Add("")
ItemsT(h).SubItems.Add("")
ItemsT(h).SubItems.Add("")
ListViewTables.Items.Add(ItemsT(h))
ItemsT(h).BackColor = 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()
ShowColumnsInListView()
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()
ShowColumnsInListView()
End If
End If
End Sub
Private Sub ShowColumnsInListView()
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).SubItems.Add(str1)
ItemsC(i).SubItems.Add(str2)
ItemsC(i).SubItems.Add(str3)
ListViewColumns.Items.Add(ItemsC(i))
If i Mod 2 = 0 Then
ItemsC(i).BackColor = Color.FloralWhite
Else
ItemsC(i).BackColor = Color.Moccasin
End If
ElseIf str = "No Entry" Then
ItemsC(i).SubItems.Add("")
ItemsC(i).SubItems.Add("")
ItemsC(i).SubItems.Add("")
ListViewColumns.Items.Add(ItemsC(i))
ItemsC(i).BackColor = Color.Moccasin
End If
Next
ListViewColumns.EndUpdate()
End Sub

E & O.E

Bob
 
S

StriderBob

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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.ColumnHeader
Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ListViewColumns = New System.Windows.Forms.ListView
Me.ColumnHeader12 = New System.Windows.Forms.ColumnHeader
Me.ListViewTables = New System.Windows.Forms.ListView
Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
Me.SuspendLayout()
'
'ListViewColumns
'
Me.ListViewColumns.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader12})
Me.ListViewColumns.Location = New System.Drawing.Point(16, 120)
Me.ListViewColumns.MultiSelect = False
Me.ListViewColumns.Name = "ListViewColumns"
Me.ListViewColumns.Size = New System.Drawing.Size(256, 97)
Me.ListViewColumns.TabIndex = 0
Me.ListViewColumns.View = System.Windows.Forms.View.Details
'
'ColumnHeader12
'
Me.ColumnHeader12.Text = "ColumnName"
Me.ColumnHeader12.Width = 120
'
'ListViewTables
'
Me.ListViewTables.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1})
Me.ListViewTables.Location = New System.Drawing.Point(16, 8)
Me.ListViewTables.MultiSelect = False
Me.ListViewTables.Name = "ListViewTables"
Me.ListViewTables.Size = New System.Drawing.Size(256, 97)
Me.ListViewTables.TabIndex = 1
Me.ListViewTables.View = System.Windows.Forms.View.Details
'
'ColumnHeader1
'
Me.ColumnHeader1.Text = "TableName"
Me.ColumnHeader1.Width = 120
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.ListViewTables)
Me.Controls.Add(Me.ListViewColumns)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

loading = True

ShowTablesInListView()

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

ShowColumnsInListView()

loading = False

End Sub

Private Sub ShowTablesInListView()
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.FloralWhite
Else
lvi.BackColor = Color.Moccasin
End If

ListViewTables.Items.Add(lvi)

Next
ListViewTables.EndUpdate()
End Sub

Private Sub ShowColumnsInListView()

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.FloralWhite
Else
lvi.BackColor = Color.Moccasin
End If

ListViewColumns.Items.Add(lvi)

Next
ListViewColumns.EndUpdate()
End Sub

Private Sub ListViewTables_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewTables.SelectedIndexChanged
If loading = True Then Return

ShowColumnsInListView()
End Sub
End Class
 
S

StriderBob

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.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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.ColumnHeader
Friend WithEvents TableNo As System.Windows.Forms.ColumnHeader
Friend WithEvents TableName As System.Windows.Forms.ColumnHeader
Friend WithEvents TableType As System.Windows.Forms.ColumnHeader
Friend WithEvents TableCharNo As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnType As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnName As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnCharNo As System.Windows.Forms.ColumnHeader
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ListViewColumns = New System.Windows.Forms.ListView
Me.ColumnNo = New System.Windows.Forms.ColumnHeader
Me.ListViewTables = New System.Windows.Forms.ListView
Me.TableNo = New System.Windows.Forms.ColumnHeader
Me.TableName = New System.Windows.Forms.ColumnHeader
Me.TableType = New System.Windows.Forms.ColumnHeader
Me.TableCharNo = New System.Windows.Forms.ColumnHeader
Me.ColumnType = New System.Windows.Forms.ColumnHeader
Me.ColumnName = New System.Windows.Forms.ColumnHeader
Me.ColumnCharNo = New System.Windows.Forms.ColumnHeader
Me.SuspendLayout()
'
'ListViewColumns
'
Me.ListViewColumns.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnNo, Me.ColumnName, Me.ColumnType, Me.ColumnCharNo})
Me.ListViewColumns.FullRowSelect = True
Me.ListViewColumns.GridLines = True
Me.ListViewColumns.Location = New System.Drawing.Point(444, 8)
Me.ListViewColumns.MultiSelect = False
Me.ListViewColumns.Name = "ListViewColumns"
Me.ListViewColumns.Size = New System.Drawing.Size(396, 304)
Me.ListViewColumns.TabIndex = 0
Me.ListViewColumns.View = System.Windows.Forms.View.Details
'
'ColumnNo
'
Me.ColumnNo.Text = "No"
Me.ColumnNo.Width = 30
'
'ListViewTables
'
Me.ListViewTables.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.TableNo, Me.TableName, Me.TableType, Me.TableCharNo})
Me.ListViewTables.FullRowSelect = True
Me.ListViewTables.GridLines = True
Me.ListViewTables.Location = New System.Drawing.Point(16, 8)
Me.ListViewTables.MultiSelect = False
Me.ListViewTables.Name = "ListViewTables"
Me.ListViewTables.Size = New System.Drawing.Size(394, 304)
Me.ListViewTables.TabIndex = 1
Me.ListViewTables.View = System.Windows.Forms.View.Details
'
'TableNo
'
Me.TableNo.Text = "No"
Me.TableNo.Width = 30
'
'TableName
'
Me.TableName.Text = "Table"
Me.TableName.Width = 120
'
'TableType
'
Me.TableType.Text = "Type"
Me.TableType.Width = 120
'
'TableCharNo
'
Me.TableCharNo.Text = "Character No."
Me.TableCharNo.Width = 120
'
'ColumnType
'
Me.ColumnType.Text = "Type"
Me.ColumnType.Width = 120
'
'ColumnName
'
Me.ColumnName.Text = "Column"
Me.ColumnName.Width = 120
'
'ColumnCharNo
'
Me.ColumnCharNo.Text = "Character No"
Me.ColumnCharNo.Width = 120
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(856, 325)
Me.Controls.Add(Me.ListViewTables)
Me.Controls.Add(Me.ListViewColumns)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) 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) = "TDataLength = 25"
Array(2, 1, 0) = "TDataLength = 25"
Array(2, 2, 0) = "TDataLength = 30"
Array(2, 3, 0) = "TDataLength = 30"
Array(2, 4, 0) = "TDataLength = 256"
Array(2, 5, 0) = "TDataLength = 256"
Array(2, 6, 0) = "TDataLength = 512"
Array(2, 7, 0) = "TDataLength = 512"
Array(2, 8, 0) = "TDataLength = 1024"
Array(2, 9, 0) = "TDataLength = 1024"
Array(2, 0, 1) = "CDataLength = 25"
Array(2, 0, 2) = "CDataLength = 25"
Array(2, 0, 3) = "CDataLength = 30"
Array(2, 0, 4) = "CDataLength = 30"
Array(2, 1, 1) = "CDataLength = 25"
Array(2, 1, 2) = "CDataLength = 25"
Array(2, 1, 3) = "CDataLength = 30"
Array(2, 1, 4) = "CDataLength = 30"
Array(2, 1, 5) = "CDataLength = 256"
Array(2, 1, 6) = "CDataLength = 256"
Array(2, 3, 1) = "CDataLength = 25"
Array(2, 3, 2) = "CDataLength = 30"
Array(2, 3, 3) = "CDataLength = 256"
End Sub
Private Sub StartForm1()
loading = True
ShowTablesInListView()
ListViewTables.Items(0).Selected = True
ListViewTables.Select() ' this seems to be important
ShowColumnsInListView()
loading = False
End Sub
Private Sub ShowTablesInListView()
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.Add(str1)
lvi.SubItems.Add(str2)
lvi.SubItems.Add(str3)
ListViewTables.Items.Add(lvi)
If str1 <> "" Then
If h Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhite
Else
lvi.BackColor = Color.Moccasin
End If
ElseIf str1 = "" Then
lvi.BackColor = System.Drawing.SystemColors.Window
End If
Next
ListViewTables.EndUpdate()
End Sub
Private Sub ShowColumnsInListView()
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.Add(str1)
lvi.SubItems.Add(str2)
lvi.SubItems.Add(str3)
If str1 <> "" Then
If i Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhite
Else
lvi.BackColor = Color.Moccasin
End If
ElseIf str1 = "" Then
lvi.BackColor = System.Drawing.SystemColors.Window
End If
ListViewColumns.Items.Add(lvi)
Next
ListViewColumns.EndUpdate()
End Sub
Private Sub ListViewTables_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewTables.SelectedIndexChanged
If loading = True Then Return
ShowColumnsInListView()
End Sub
Private Sub ListViewTables_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) 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
ShowColumnsInListView()
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
ShowColumnsInListView()
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(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
e.Cancel = False
End Sub
Protected Overrides Sub OnVisibleChanged(ByVal e As System.EventArgs)
If Me.Visible = True Then
StartForm1()
End If
End Sub
#End Region

End Class
 
G

Greg Burns

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


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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.ColumnHeader
Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ListViewColumns = New System.Windows.Forms.ListView
Me.ColumnHeader12 = New System.Windows.Forms.ColumnHeader
Me.ListViewTables = New System.Windows.Forms.ListView
Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
Me.SuspendLayout()
'
'ListViewColumns
'
Me.ListViewColumns.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader12})
Me.ListViewColumns.Location = New System.Drawing.Point(16, 120)
Me.ListViewColumns.MultiSelect = False
Me.ListViewColumns.Name = "ListViewColumns"
Me.ListViewColumns.Size = New System.Drawing.Size(256, 97)
Me.ListViewColumns.TabIndex = 0
Me.ListViewColumns.View = System.Windows.Forms.View.Details
'
'ColumnHeader12
'
Me.ColumnHeader12.Text = "ColumnName"
Me.ColumnHeader12.Width = 120
'
'ListViewTables
'
Me.ListViewTables.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1})
Me.ListViewTables.Location = New System.Drawing.Point(16, 8)
Me.ListViewTables.MultiSelect = False
Me.ListViewTables.Name = "ListViewTables"
Me.ListViewTables.Size = New System.Drawing.Size(256, 97)
Me.ListViewTables.TabIndex = 1
Me.ListViewTables.View = System.Windows.Forms.View.Details
'
'ColumnHeader1
'
Me.ColumnHeader1.Text = "TableName"
Me.ColumnHeader1.Width = 120
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.ListViewTables)
Me.Controls.Add(Me.ListViewColumns)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

loading = True

ShowTablesInListView()

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

ShowColumnsInListView()

loading = False

End Sub

Private Sub ShowTablesInListView()
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.FloralWhite
Else
lvi.BackColor = Color.Moccasin
End If

ListViewTables.Items.Add(lvi)

Next
ListViewTables.EndUpdate()
End Sub

Private Sub ShowColumnsInListView()

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.FloralWhite
Else
lvi.BackColor = Color.Moccasin
End If

ListViewColumns.Items.Add(lvi)

Next
ListViewColumns.EndUpdate()
End Sub

Private Sub ListViewTables_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewTables.SelectedIndexChanged
If loading = True Then Return

ShowColumnsInListView()
End Sub
End Class
 
G

Greg Burns

Why are you handling ListViewTables.KeyDown? ListViewTables.SelectedIndexChanged takes care of this automatically for you. (Both selection by keyboard and the mouse)

Looks like you are trying to track tblPosn from the KeyDown event. But notice in my new ShowColumnsInListView that I've made a new tblPosn variable that is shadowing your global form level one. You can determine tblPosn using ListViewTables.SelectedItems(0).Index without needing to use KeyDown at all.

Here is the code again with KeyDown event and tblPosn commented out. Appears to function the same.

Greg


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.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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.ColumnHeader
Friend WithEvents TableNo As System.Windows.Forms.ColumnHeader
Friend WithEvents TableName As System.Windows.Forms.ColumnHeader
Friend WithEvents TableType As System.Windows.Forms.ColumnHeader
Friend WithEvents TableCharNo As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnType As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnName As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnCharNo As System.Windows.Forms.ColumnHeader
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ListViewColumns = New System.Windows.Forms.ListView
Me.ColumnNo = New System.Windows.Forms.ColumnHeader
Me.ListViewTables = New System.Windows.Forms.ListView
Me.TableNo = New System.Windows.Forms.ColumnHeader
Me.TableName = New System.Windows.Forms.ColumnHeader
Me.TableType = New System.Windows.Forms.ColumnHeader
Me.TableCharNo = New System.Windows.Forms.ColumnHeader
Me.ColumnType = New System.Windows.Forms.ColumnHeader
Me.ColumnName = New System.Windows.Forms.ColumnHeader
Me.ColumnCharNo = New System.Windows.Forms.ColumnHeader
Me.SuspendLayout()
'
'ListViewColumns
'
Me.ListViewColumns.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnNo, Me.ColumnName, Me.ColumnType, Me.ColumnCharNo})
Me.ListViewColumns.FullRowSelect = True
Me.ListViewColumns.GridLines = True
Me.ListViewColumns.Location = New System.Drawing.Point(444, 8)
Me.ListViewColumns.MultiSelect = False
Me.ListViewColumns.Name = "ListViewColumns"
Me.ListViewColumns.Size = New System.Drawing.Size(396, 304)
Me.ListViewColumns.TabIndex = 0
Me.ListViewColumns.View = System.Windows.Forms.View.Details
'
'ColumnNo
'
Me.ColumnNo.Text = "No"
Me.ColumnNo.Width = 30
'
'ListViewTables
'
Me.ListViewTables.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.TableNo, Me.TableName, Me.TableType, Me.TableCharNo})
Me.ListViewTables.FullRowSelect = True
Me.ListViewTables.GridLines = True
Me.ListViewTables.Location = New System.Drawing.Point(16, 8)
Me.ListViewTables.MultiSelect = False
Me.ListViewTables.Name = "ListViewTables"
Me.ListViewTables.Size = New System.Drawing.Size(394, 304)
Me.ListViewTables.TabIndex = 1
Me.ListViewTables.View = System.Windows.Forms.View.Details
'
'TableNo
'
Me.TableNo.Text = "No"
Me.TableNo.Width = 30
'
'TableName
'
Me.TableName.Text = "Table"
Me.TableName.Width = 120
'
'TableType
'
Me.TableType.Text = "Type"
Me.TableType.Width = 120
'
'TableCharNo
'
Me.TableCharNo.Text = "Character No."
Me.TableCharNo.Width = 120
'
'ColumnType
'
Me.ColumnType.Text = "Type"
Me.ColumnType.Width = 120
'
'ColumnName
'
Me.ColumnName.Text = "Column"
Me.ColumnName.Width = 120
'
'ColumnCharNo
'
Me.ColumnCharNo.Text = "Character No"
Me.ColumnCharNo.Width = 120
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(856, 325)
Me.Controls.Add(Me.ListViewTables)
Me.Controls.Add(Me.ListViewColumns)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) 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) = "TDataLength = 25"
Array(2, 1, 0) = "TDataLength = 25"
Array(2, 2, 0) = "TDataLength = 30"
Array(2, 3, 0) = "TDataLength = 30"
Array(2, 4, 0) = "TDataLength = 256"
Array(2, 5, 0) = "TDataLength = 256"
Array(2, 6, 0) = "TDataLength = 512"
Array(2, 7, 0) = "TDataLength = 512"
Array(2, 8, 0) = "TDataLength = 1024"
Array(2, 9, 0) = "TDataLength = 1024"
Array(2, 0, 1) = "CDataLength = 25"
Array(2, 0, 2) = "CDataLength = 25"
Array(2, 0, 3) = "CDataLength = 30"
Array(2, 0, 4) = "CDataLength = 30"
Array(2, 1, 1) = "CDataLength = 25"
Array(2, 1, 2) = "CDataLength = 25"
Array(2, 1, 3) = "CDataLength = 30"
Array(2, 1, 4) = "CDataLength = 30"
Array(2, 1, 5) = "CDataLength = 256"
Array(2, 1, 6) = "CDataLength = 256"
Array(2, 3, 1) = "CDataLength = 25"
Array(2, 3, 2) = "CDataLength = 30"
Array(2, 3, 3) = "CDataLength = 256"
End Sub
Private Sub StartForm1()
loading = True
ShowTablesInListView()
ListViewTables.Items(0).Selected = True
ListViewTables.Select() ' this seems to be important
ShowColumnsInListView()
loading = False
End Sub
Private Sub ShowTablesInListView()
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.Add(str1)
lvi.SubItems.Add(str2)
lvi.SubItems.Add(str3)
ListViewTables.Items.Add(lvi)
If str1 <> "" Then
If h Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhite
Else
lvi.BackColor = Color.Moccasin
End If
ElseIf str1 = "" Then
lvi.BackColor = System.Drawing.SystemColors.Window
End If
Next
ListViewTables.EndUpdate()
End Sub
Private Sub ShowColumnsInListView()
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.Add(str1)
lvi.SubItems.Add(str2)
lvi.SubItems.Add(str3)
If str1 <> "" Then
If i Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhite
Else
lvi.BackColor = Color.Moccasin
End If
ElseIf str1 = "" Then
lvi.BackColor = System.Drawing.SystemColors.Window
End If
ListViewColumns.Items.Add(lvi)
Next
ListViewColumns.EndUpdate()
End Sub
Private Sub ListViewTables_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewTables.SelectedIndexChanged
If loading = True Then Return
ShowColumnsInListView()
End Sub
'Private Sub ListViewTables_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) 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
' ShowColumnsInListView()
' 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
' ShowColumnsInListView()
' 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(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
e.Cancel = False
End Sub
Protected Overrides Sub OnVisibleChanged(ByVal e As System.EventArgs)
If Me.Visible = True Then
StartForm1()
End If
End Sub
#End Region

End Class
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.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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.ColumnHeader
Friend WithEvents TableNo As System.Windows.Forms.ColumnHeader
Friend WithEvents TableName As System.Windows.Forms.ColumnHeader
Friend WithEvents TableType As System.Windows.Forms.ColumnHeader
Friend WithEvents TableCharNo As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnType As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnName As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnCharNo As System.Windows.Forms.ColumnHeader
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ListViewColumns = New System.Windows.Forms.ListView
Me.ColumnNo = New System.Windows.Forms.ColumnHeader
Me.ListViewTables = New System.Windows.Forms.ListView
Me.TableNo = New System.Windows.Forms.ColumnHeader
Me.TableName = New System.Windows.Forms.ColumnHeader
Me.TableType = New System.Windows.Forms.ColumnHeader
Me.TableCharNo = New System.Windows.Forms.ColumnHeader
Me.ColumnType = New System.Windows.Forms.ColumnHeader
Me.ColumnName = New System.Windows.Forms.ColumnHeader
Me.ColumnCharNo = New System.Windows.Forms.ColumnHeader
Me.SuspendLayout()
'
'ListViewColumns
'
Me.ListViewColumns.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnNo, Me.ColumnName, Me.ColumnType, Me.ColumnCharNo})
Me.ListViewColumns.FullRowSelect = True
Me.ListViewColumns.GridLines = True
Me.ListViewColumns.Location = New System.Drawing.Point(444, 8)
Me.ListViewColumns.MultiSelect = False
Me.ListViewColumns.Name = "ListViewColumns"
Me.ListViewColumns.Size = New System.Drawing.Size(396, 304)
Me.ListViewColumns.TabIndex = 0
Me.ListViewColumns.View = System.Windows.Forms.View.Details
'
'ColumnNo
'
Me.ColumnNo.Text = "No"
Me.ColumnNo.Width = 30
'
'ListViewTables
'
Me.ListViewTables.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.TableNo, Me.TableName, Me.TableType, Me.TableCharNo})
Me.ListViewTables.FullRowSelect = True
Me.ListViewTables.GridLines = True
Me.ListViewTables.Location = New System.Drawing.Point(16, 8)
Me.ListViewTables.MultiSelect = False
Me.ListViewTables.Name = "ListViewTables"
Me.ListViewTables.Size = New System.Drawing.Size(394, 304)
Me.ListViewTables.TabIndex = 1
Me.ListViewTables.View = System.Windows.Forms.View.Details
'
'TableNo
'
Me.TableNo.Text = "No"
Me.TableNo.Width = 30
'
'TableName
'
Me.TableName.Text = "Table"
Me.TableName.Width = 120
'
'TableType
'
Me.TableType.Text = "Type"
Me.TableType.Width = 120
'
'TableCharNo
'
Me.TableCharNo.Text = "Character No."
Me.TableCharNo.Width = 120
'
'ColumnType
'
Me.ColumnType.Text = "Type"
Me.ColumnType.Width = 120
'
'ColumnName
'
Me.ColumnName.Text = "Column"
Me.ColumnName.Width = 120
'
'ColumnCharNo
'
Me.ColumnCharNo.Text = "Character No"
Me.ColumnCharNo.Width = 120
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(856, 325)
Me.Controls.Add(Me.ListViewTables)
Me.Controls.Add(Me.ListViewColumns)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) 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) = "TDataLength = 25"
Array(2, 1, 0) = "TDataLength = 25"
Array(2, 2, 0) = "TDataLength = 30"
Array(2, 3, 0) = "TDataLength = 30"
Array(2, 4, 0) = "TDataLength = 256"
Array(2, 5, 0) = "TDataLength = 256"
Array(2, 6, 0) = "TDataLength = 512"
Array(2, 7, 0) = "TDataLength = 512"
Array(2, 8, 0) = "TDataLength = 1024"
Array(2, 9, 0) = "TDataLength = 1024"
Array(2, 0, 1) = "CDataLength = 25"
Array(2, 0, 2) = "CDataLength = 25"
Array(2, 0, 3) = "CDataLength = 30"
Array(2, 0, 4) = "CDataLength = 30"
Array(2, 1, 1) = "CDataLength = 25"
Array(2, 1, 2) = "CDataLength = 25"
Array(2, 1, 3) = "CDataLength = 30"
Array(2, 1, 4) = "CDataLength = 30"
Array(2, 1, 5) = "CDataLength = 256"
Array(2, 1, 6) = "CDataLength = 256"
Array(2, 3, 1) = "CDataLength = 25"
Array(2, 3, 2) = "CDataLength = 30"
Array(2, 3, 3) = "CDataLength = 256"
End Sub
Private Sub StartForm1()
loading = True
ShowTablesInListView()
ListViewTables.Items(0).Selected = True
ListViewTables.Select() ' this seems to be important
ShowColumnsInListView()
loading = False
End Sub
Private Sub ShowTablesInListView()
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.Add(str1)
lvi.SubItems.Add(str2)
lvi.SubItems.Add(str3)
ListViewTables.Items.Add(lvi)
If str1 <> "" Then
If h Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhite
Else
lvi.BackColor = Color.Moccasin
End If
ElseIf str1 = "" Then
lvi.BackColor = System.Drawing.SystemColors.Window
End If
Next
ListViewTables.EndUpdate()
End Sub
Private Sub ShowColumnsInListView()
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.Add(str1)
lvi.SubItems.Add(str2)
lvi.SubItems.Add(str3)
If str1 <> "" Then
If i Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhite
Else
lvi.BackColor = Color.Moccasin
End If
ElseIf str1 = "" Then
lvi.BackColor = System.Drawing.SystemColors.Window
End If
ListViewColumns.Items.Add(lvi)
Next
ListViewColumns.EndUpdate()
End Sub
Private Sub ListViewTables_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewTables.SelectedIndexChanged
If loading = True Then Return
ShowColumnsInListView()
End Sub
Private Sub ListViewTables_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) 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
ShowColumnsInListView()
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
ShowColumnsInListView()
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(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
e.Cancel = False
End Sub
Protected Overrides Sub OnVisibleChanged(ByVal e As System.EventArgs)
If Me.Visible = True Then
StartForm1()
End If
End Sub
#End Region

End Class
 
S

StriderBob

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 ?
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
 
S

StriderBob

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

Why are you handling ListViewTables.KeyDown? ListViewTables.SelectedIndexChanged takes care of this automatically for you. (Both selection by keyboard and the mouse)

Looks like you are trying to track tblPosn from the KeyDown event. But notice in my new ShowColumnsInListView that I've made a new tblPosn variable that is shadowing your global form level one. You can determine tblPosn using ListViewTables.SelectedItems(0).Index without needing to use KeyDown at all.

Here is the code again with KeyDown event and tblPosn commented out. Appears to function the same.

Greg


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.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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.ColumnHeader
Friend WithEvents TableNo As System.Windows.Forms.ColumnHeader
Friend WithEvents TableName As System.Windows.Forms.ColumnHeader
Friend WithEvents TableType As System.Windows.Forms.ColumnHeader
Friend WithEvents TableCharNo As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnType As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnName As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnCharNo As System.Windows.Forms.ColumnHeader
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ListViewColumns = New System.Windows.Forms.ListView
Me.ColumnNo = New System.Windows.Forms.ColumnHeader
Me.ListViewTables = New System.Windows.Forms.ListView
Me.TableNo = New System.Windows.Forms.ColumnHeader
Me.TableName = New System.Windows.Forms.ColumnHeader
Me.TableType = New System.Windows.Forms.ColumnHeader
Me.TableCharNo = New System.Windows.Forms.ColumnHeader
Me.ColumnType = New System.Windows.Forms.ColumnHeader
Me.ColumnName = New System.Windows.Forms.ColumnHeader
Me.ColumnCharNo = New System.Windows.Forms.ColumnHeader
Me.SuspendLayout()
'
'ListViewColumns
'
Me.ListViewColumns.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnNo, Me.ColumnName, Me.ColumnType, Me.ColumnCharNo})
Me.ListViewColumns.FullRowSelect = True
Me.ListViewColumns.GridLines = True
Me.ListViewColumns.Location = New System.Drawing.Point(444, 8)
Me.ListViewColumns.MultiSelect = False
Me.ListViewColumns.Name = "ListViewColumns"
Me.ListViewColumns.Size = New System.Drawing.Size(396, 304)
Me.ListViewColumns.TabIndex = 0
Me.ListViewColumns.View = System.Windows.Forms.View.Details
'
'ColumnNo
'
Me.ColumnNo.Text = "No"
Me.ColumnNo.Width = 30
'
'ListViewTables
'
Me.ListViewTables.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.TableNo, Me.TableName, Me.TableType, Me.TableCharNo})
Me.ListViewTables.FullRowSelect = True
Me.ListViewTables.GridLines = True
Me.ListViewTables.Location = New System.Drawing.Point(16, 8)
Me.ListViewTables.MultiSelect = False
Me.ListViewTables.Name = "ListViewTables"
Me.ListViewTables.Size = New System.Drawing.Size(394, 304)
Me.ListViewTables.TabIndex = 1
Me.ListViewTables.View = System.Windows.Forms.View.Details
'
'TableNo
'
Me.TableNo.Text = "No"
Me.TableNo.Width = 30
'
'TableName
'
Me.TableName.Text = "Table"
Me.TableName.Width = 120
'
'TableType
'
Me.TableType.Text = "Type"
Me.TableType.Width = 120
'
'TableCharNo
'
Me.TableCharNo.Text = "Character No."
Me.TableCharNo.Width = 120
'
'ColumnType
'
Me.ColumnType.Text = "Type"
Me.ColumnType.Width = 120
'
'ColumnName
'
Me.ColumnName.Text = "Column"
Me.ColumnName.Width = 120
'
'ColumnCharNo
'
Me.ColumnCharNo.Text = "Character No"
Me.ColumnCharNo.Width = 120
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(856, 325)
Me.Controls.Add(Me.ListViewTables)
Me.Controls.Add(Me.ListViewColumns)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) 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) = "TDataLength = 25"
Array(2, 1, 0) = "TDataLength = 25"
Array(2, 2, 0) = "TDataLength = 30"
Array(2, 3, 0) = "TDataLength = 30"
Array(2, 4, 0) = "TDataLength = 256"
Array(2, 5, 0) = "TDataLength = 256"
Array(2, 6, 0) = "TDataLength = 512"
Array(2, 7, 0) = "TDataLength = 512"
Array(2, 8, 0) = "TDataLength = 1024"
Array(2, 9, 0) = "TDataLength = 1024"
Array(2, 0, 1) = "CDataLength = 25"
Array(2, 0, 2) = "CDataLength = 25"
Array(2, 0, 3) = "CDataLength = 30"
Array(2, 0, 4) = "CDataLength = 30"
Array(2, 1, 1) = "CDataLength = 25"
Array(2, 1, 2) = "CDataLength = 25"
Array(2, 1, 3) = "CDataLength = 30"
Array(2, 1, 4) = "CDataLength = 30"
Array(2, 1, 5) = "CDataLength = 256"
Array(2, 1, 6) = "CDataLength = 256"
Array(2, 3, 1) = "CDataLength = 25"
Array(2, 3, 2) = "CDataLength = 30"
Array(2, 3, 3) = "CDataLength = 256"
End Sub
Private Sub StartForm1()
loading = True
ShowTablesInListView()
ListViewTables.Items(0).Selected = True
ListViewTables.Select() ' this seems to be important
ShowColumnsInListView()
loading = False
End Sub
Private Sub ShowTablesInListView()
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.Add(str1)
lvi.SubItems.Add(str2)
lvi.SubItems.Add(str3)
ListViewTables.Items.Add(lvi)
If str1 <> "" Then
If h Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhite
Else
lvi.BackColor = Color.Moccasin
End If
ElseIf str1 = "" Then
lvi.BackColor = System.Drawing.SystemColors.Window
End If
Next
ListViewTables.EndUpdate()
End Sub
Private Sub ShowColumnsInListView()
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.Add(str1)
lvi.SubItems.Add(str2)
lvi.SubItems.Add(str3)
If str1 <> "" Then
If i Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhite
Else
lvi.BackColor = Color.Moccasin
End If
ElseIf str1 = "" Then
lvi.BackColor = System.Drawing.SystemColors.Window
End If
ListViewColumns.Items.Add(lvi)
Next
ListViewColumns.EndUpdate()
End Sub
Private Sub ListViewTables_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewTables.SelectedIndexChanged
If loading = True Then Return
ShowColumnsInListView()
End Sub
'Private Sub ListViewTables_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) 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
' ShowColumnsInListView()
' 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
' ShowColumnsInListView()
' 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(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
e.Cancel = False
End Sub
Protected Overrides Sub OnVisibleChanged(ByVal e As System.EventArgs)
If Me.Visible = True Then
StartForm1()
End If
End Sub
#End Region

End Class
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.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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.ColumnHeader
Friend WithEvents TableNo As System.Windows.Forms.ColumnHeader
Friend WithEvents TableName As System.Windows.Forms.ColumnHeader
Friend WithEvents TableType As System.Windows.Forms.ColumnHeader
Friend WithEvents TableCharNo As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnType As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnName As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnCharNo As System.Windows.Forms.ColumnHeader
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ListViewColumns = New System.Windows.Forms.ListView
Me.ColumnNo = New System.Windows.Forms.ColumnHeader
Me.ListViewTables = New System.Windows.Forms.ListView
Me.TableNo = New System.Windows.Forms.ColumnHeader
Me.TableName = New System.Windows.Forms.ColumnHeader
Me.TableType = New System.Windows.Forms.ColumnHeader
Me.TableCharNo = New System.Windows.Forms.ColumnHeader
Me.ColumnType = New System.Windows.Forms.ColumnHeader
Me.ColumnName = New System.Windows.Forms.ColumnHeader
Me.ColumnCharNo = New System.Windows.Forms.ColumnHeader
Me.SuspendLayout()
'
'ListViewColumns
'
Me.ListViewColumns.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnNo, Me.ColumnName, Me.ColumnType, Me.ColumnCharNo})
Me.ListViewColumns.FullRowSelect = True
Me.ListViewColumns.GridLines = True
Me.ListViewColumns.Location = New System.Drawing.Point(444, 8)
Me.ListViewColumns.MultiSelect = False
Me.ListViewColumns.Name = "ListViewColumns"
Me.ListViewColumns.Size = New System.Drawing.Size(396, 304)
Me.ListViewColumns.TabIndex = 0
Me.ListViewColumns.View = System.Windows.Forms.View.Details
'
'ColumnNo
'
Me.ColumnNo.Text = "No"
Me.ColumnNo.Width = 30
'
'ListViewTables
'
Me.ListViewTables.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.TableNo, Me.TableName, Me.TableType, Me.TableCharNo})
Me.ListViewTables.FullRowSelect = True
Me.ListViewTables.GridLines = True
Me.ListViewTables.Location = New System.Drawing.Point(16, 8)
Me.ListViewTables.MultiSelect = False
Me.ListViewTables.Name = "ListViewTables"
Me.ListViewTables.Size = New System.Drawing.Size(394, 304)
Me.ListViewTables.TabIndex = 1
Me.ListViewTables.View = System.Windows.Forms.View.Details
'
'TableNo
'
Me.TableNo.Text = "No"
Me.TableNo.Width = 30
'
'TableName
'
Me.TableName.Text = "Table"
Me.TableName.Width = 120
'
'TableType
'
Me.TableType.Text = "Type"
Me.TableType.Width = 120
'
'TableCharNo
'
Me.TableCharNo.Text = "Character No."
Me.TableCharNo.Width = 120
'
'ColumnType
'
Me.ColumnType.Text = "Type"
Me.ColumnType.Width = 120
'
'ColumnName
'
Me.ColumnName.Text = "Column"
Me.ColumnName.Width = 120
'
'ColumnCharNo
'
Me.ColumnCharNo.Text = "Character No"
Me.ColumnCharNo.Width = 120
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(856, 325)
Me.Controls.Add(Me.ListViewTables)
Me.Controls.Add(Me.ListViewColumns)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) 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) = "TDataLength = 25"
Array(2, 1, 0) = "TDataLength = 25"
Array(2, 2, 0) = "TDataLength = 30"
Array(2, 3, 0) = "TDataLength = 30"
Array(2, 4, 0) = "TDataLength = 256"
Array(2, 5, 0) = "TDataLength = 256"
Array(2, 6, 0) = "TDataLength = 512"
Array(2, 7, 0) = "TDataLength = 512"
Array(2, 8, 0) = "TDataLength = 1024"
Array(2, 9, 0) = "TDataLength = 1024"
Array(2, 0, 1) = "CDataLength = 25"
Array(2, 0, 2) = "CDataLength = 25"
Array(2, 0, 3) = "CDataLength = 30"
Array(2, 0, 4) = "CDataLength = 30"
Array(2, 1, 1) = "CDataLength = 25"
Array(2, 1, 2) = "CDataLength = 25"
Array(2, 1, 3) = "CDataLength = 30"
Array(2, 1, 4) = "CDataLength = 30"
Array(2, 1, 5) = "CDataLength = 256"
Array(2, 1, 6) = "CDataLength = 256"
Array(2, 3, 1) = "CDataLength = 25"
Array(2, 3, 2) = "CDataLength = 30"
Array(2, 3, 3) = "CDataLength = 256"
End Sub
Private Sub StartForm1()
loading = True
ShowTablesInListView()
ListViewTables.Items(0).Selected = True
ListViewTables.Select() ' this seems to be important
ShowColumnsInListView()
loading = False
End Sub
Private Sub ShowTablesInListView()
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.Add(str1)
lvi.SubItems.Add(str2)
lvi.SubItems.Add(str3)
ListViewTables.Items.Add(lvi)
If str1 <> "" Then
If h Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhite
Else
lvi.BackColor = Color.Moccasin
End If
ElseIf str1 = "" Then
lvi.BackColor = System.Drawing.SystemColors.Window
End If
Next
ListViewTables.EndUpdate()
End Sub
Private Sub ShowColumnsInListView()
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.Add(str1)
lvi.SubItems.Add(str2)
lvi.SubItems.Add(str3)
If str1 <> "" Then
If i Mod 2 = 0 Then
lvi.BackColor = Color.FloralWhite
Else
lvi.BackColor = Color.Moccasin
End If
ElseIf str1 = "" Then
lvi.BackColor = System.Drawing.SystemColors.Window
End If
ListViewColumns.Items.Add(lvi)
Next
ListViewColumns.EndUpdate()
End Sub
Private Sub ListViewTables_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewTables.SelectedIndexChanged
If loading = True Then Return
ShowColumnsInListView()
End Sub
Private Sub ListViewTables_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) 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
ShowColumnsInListView()
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
ShowColumnsInListView()
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(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
e.Cancel = False
End Sub
Protected Overrides Sub OnVisibleChanged(ByVal e As System.EventArgs)
If Me.Visible = True Then
StartForm1()
End If
End Sub
#End Region

End Class
 
G

Greg Burns

Why would no items be selected?

ShowColumnsInListView is called in your SelectedIndexChanged event. That only gets called after something gets selected (or unselected).

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

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=True to have this happen).

Greg


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
 
G

Greg Burns

Post some code. :^)
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 ?
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
 
S

StriderBob

I'm confused !

Surely no items would be selected because of the (0).
As I read the line "Dim tblPosn As Integer = ListViewTables.SelectedItems(0).Index"

We set the variable tblPosn to the ListViewTables's SelectedItems(0) ie. there are either zero items selected Or we are looking at the item at index position zero, i.e the first item ?

I understand everything else you mentioned and concurr, normally in for example a listbox I would use something like :-

Private Sub ListBoxTables_SelectedIndexChanged(. . . . . etc . . . . .)
If Loading = True Then Exit Sub
tblPosn = ListBoxTables.SelectedIndex
ShowColumnsInListBox()
End Sub

It's specifically the (0).Index I'm not understanding.

Bob
Why would no items be selected?

ShowColumnsInListView is called in your SelectedIndexChanged event. That only gets called after something gets selected (or unselected).

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

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=True to have this happen).

Greg


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
 
G

Greg Burns

"ListView.SelectedListViewItemCollection"

Represents the collection of selected items in a list view control.

It is a collection of the selected items ONLY. 0 being the index of the first selected item (and only possible item if MultiSelect=false). This all makes more sense if MultiSelect=true. When only one item can be selected it does seems rather strange syntax.

If no items are selected the collection is empty. Hence why I check first before trying to access the first item (0-based).

If ListViewTables.SelectedIndices.Count = 0 Then Return

Greg

I'm confused !

Surely no items would be selected because of the (0).
As I read the line "Dim tblPosn As Integer = ListViewTables.SelectedItems(0).Index"

We set the variable tblPosn to the ListViewTables's SelectedItems(0) ie. there are either zero items selected Or we are looking at the item at index position zero, i.e the first item ?

I understand everything else you mentioned and concurr, normally in for example a listbox I would use something like :-

Private Sub ListBoxTables_SelectedIndexChanged(. . . . . etc . . . . ..)
If Loading = True Then Exit Sub
tblPosn = ListBoxTables.SelectedIndex
ShowColumnsInListBox()
End Sub

It's specifically the (0).Index I'm not understanding.

Bob
Why would no items be selected?

ShowColumnsInListView is called in your SelectedIndexChanged event. That only gets called after something gets selected (or unselected).

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

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=True to have this happen).

Greg


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
 
S

StriderBob

OK Here's the basic code, followed by one attempt to handle the event, I cannot remember how many attempts I made but the problem was on three newsgroups for at least two weeks. I got not one answe rof any type!

The Images are simply a Red Square 48 x 48 and Green Square 48 x 48

The Module :-

Module Module1
Public FormBtn1 As New Form2
Public FormBtn2 As New Form3
End Module

The Parent Form :-

Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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 MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.MenuItem3 = New System.Windows.Forms.MenuItem
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem2, Me.MenuItem3})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.Text = "&File"
'
'MenuItem2
'
Me.MenuItem2.Index = 1
Me.MenuItem2.MdiList = True
Me.MenuItem2.Text = "&Window"
'
'MenuItem3
'
Me.MenuItem3.Index = 2
Me.MenuItem3.Text = "&Help"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.IsMdiContainer = True
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Form1"
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FormBtn1.MdiParent = Me
FormBtn2.MdiParent = Me
FormBtn1.Show()
End Sub
End Class

The First Child Form :-

Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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 Button1 As System.Windows.Forms.Button
Friend WithEvents ImageListButton1 As System.Windows.Forms.ImageList
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form2))
Me.Button1 = New System.Windows.Forms.Button
Me.ImageListButton1 = New System.Windows.Forms.ImageList(Me.components)
Me.SuspendLayout()
'
'Button1
'
Me.Button1.ImageIndex = 0
Me.Button1.ImageList = Me.ImageListButton1
Me.Button1.Location = New System.Drawing.Point(8, 8)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(48, 48)
Me.Button1.TabIndex = 0
'
'ImageListButton1
'
Me.ImageListButton1.ImageSize = New System.Drawing.Size(48, 48)
Me.ImageListButton1.ImageStream = CType(resources.GetObject("ImageListButton1.ImageStream"), System.Windows.Forms.ImageListStreamer)
Me.ImageListButton1.TransparentColor = System.Drawing.Color.Black
'
'Form2
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Button1)
Me.Name = "Form2"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
Me.Text = "Form2"
Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FormBtn1.Hide()
FormBtn2.Show()
End Sub
Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
Button1.ImageIndex = 1
End Sub
Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
Button1.ImageIndex = 0
End Sub
End Class

The Second Child Form :-

Public Class Form3
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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 Button1 As System.Windows.Forms.Button
Friend WithEvents ImageListButton1 As System.Windows.Forms.ImageList
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form3))
Me.Button1 = New System.Windows.Forms.Button
Me.ImageListButton1 = New System.Windows.Forms.ImageList(Me.components)
Me.SuspendLayout()
'
'Button1
'
Me.Button1.ImageIndex = 0
Me.Button1.ImageList = Me.ImageListButton1
Me.Button1.Location = New System.Drawing.Point(236, 220)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(48, 48)
Me.Button1.TabIndex = 0
'
'ImageListButton1
'
Me.ImageListButton1.ImageSize = New System.Drawing.Size(48, 48)
Me.ImageListButton1.ImageStream = CType(resources.GetObject("ImageListButton1.ImageStream"), System.Windows.Forms.ImageListStreamer)
Me.ImageListButton1.TransparentColor = System.Drawing.Color.Black
'
'Form3
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Button1)
Me.Name = "Form3"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
Me.Text = "Form3"
Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FormBtn2.Hide()
FormBtn1.Show()
End Sub
Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
Button1.ImageIndex = 1
End Sub
Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
Button1.ImageIndex = 0
End Sub
End Class


As I recall one of my handling attempts was :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AddHandler Me.Button1.MouseLeave, AddressOf Me.Button1_MouseLeave
FormBtn2.Hide()
FormBtn1.Show()
End Sub

It was seveal weeks ago and I've since deleted all the input and redesigned the project. A shame it looked a lot cooler that the clunky standard buttons. Give me a clue and I'll go back.

Bob

Post some code. :^)
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 ?
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
 
G

Greg Burns

I see the issue. I just got it to lock the image and stop changing the button picture. I'll see what I can figure out a little later on...

(Not to sound aloof, but posting in html is usually fround upon. There is an option in OE to send all news items in Plain Text...)

Greg

OK Here's the basic code, followed by one attempt to handle the event, I cannot remember how many attempts I made but the problem was on three newsgroups for at least two weeks. I got not one answe rof any type!

The Images are simply a Red Square 48 x 48 and Green Square 48 x 48

The Module :-

Module Module1
Public FormBtn1 As New Form2
Public FormBtn2 As New Form3
End Module

The Parent Form :-

Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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 MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.MenuItem3 = New System.Windows.Forms.MenuItem
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem2, Me.MenuItem3})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.Text = "&File"
'
'MenuItem2
'
Me.MenuItem2.Index = 1
Me.MenuItem2.MdiList = True
Me.MenuItem2.Text = "&Window"
'
'MenuItem3
'
Me.MenuItem3.Index = 2
Me.MenuItem3.Text = "&Help"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.IsMdiContainer = True
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Form1"
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FormBtn1.MdiParent = Me
FormBtn2.MdiParent = Me
FormBtn1.Show()
End Sub
End Class

The First Child Form :-

Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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 Button1 As System.Windows.Forms.Button
Friend WithEvents ImageListButton1 As System.Windows.Forms.ImageList
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form2))
Me.Button1 = New System.Windows.Forms.Button
Me.ImageListButton1 = New System.Windows.Forms.ImageList(Me.components)
Me.SuspendLayout()
'
'Button1
'
Me.Button1.ImageIndex = 0
Me.Button1.ImageList = Me.ImageListButton1
Me.Button1.Location = New System.Drawing.Point(8, 8)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(48, 48)
Me.Button1.TabIndex = 0
'
'ImageListButton1
'
Me.ImageListButton1.ImageSize = New System.Drawing.Size(48, 48)
Me.ImageListButton1.ImageStream = CType(resources.GetObject("ImageListButton1.ImageStream"), System.Windows.Forms.ImageListStreamer)
Me.ImageListButton1.TransparentColor = System.Drawing.Color.Black
'
'Form2
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Button1)
Me.Name = "Form2"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
Me.Text = "Form2"
Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FormBtn1.Hide()
FormBtn2.Show()
End Sub
Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
Button1.ImageIndex = 1
End Sub
Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
Button1.ImageIndex = 0
End Sub
End Class

The Second Child Form :-

Public Class Form3
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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 Button1 As System.Windows.Forms.Button
Friend WithEvents ImageListButton1 As System.Windows.Forms.ImageList
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form3))
Me.Button1 = New System.Windows.Forms.Button
Me.ImageListButton1 = New System.Windows.Forms.ImageList(Me.components)
Me.SuspendLayout()
'
'Button1
'
Me.Button1.ImageIndex = 0
Me.Button1.ImageList = Me.ImageListButton1
Me.Button1.Location = New System.Drawing.Point(236, 220)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(48, 48)
Me.Button1.TabIndex = 0
'
'ImageListButton1
'
Me.ImageListButton1.ImageSize = New System.Drawing.Size(48, 48)
Me.ImageListButton1.ImageStream = CType(resources.GetObject("ImageListButton1.ImageStream"), System.Windows.Forms.ImageListStreamer)
Me.ImageListButton1.TransparentColor = System.Drawing.Color.Black
'
'Form3
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Button1)
Me.Name = "Form3"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
Me.Text = "Form3"
Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FormBtn2.Hide()
FormBtn1.Show()
End Sub
Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
Button1.ImageIndex = 1
End Sub
Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
Button1.ImageIndex = 0
End Sub
End Class


As I recall one of my handling attempts was :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AddHandler Me.Button1.MouseLeave, AddressOf Me.Button1_MouseLeave
FormBtn2.Hide()
FormBtn1.Show()
End Sub

It was seveal weeks ago and I've since deleted all the input and redesigned the project. A shame it looked a lot cooler that the clunky standard buttons. Give me a clue and I'll go back.

Bob

Post some code. :^)
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 ?
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
 
S

StriderBob

Thanks for the explanation now it starts to make sense.

Sorry about html I'v just been replying on your awsome coloured form after
clearing some endless repetitions. It's probably time we stopped meeting
like this anyway. People will start to talk!!!

Bob
 
G

Greg Burns

My point was:

I find it much quicker to help oneself. Waiting 2 days for somebody from MS
to tell you they will look into it is FRUSTRATING.

Second, HAVE YOU REGISTERED your email alais for MSDN managed newsgroups? If
not, how is MS suppose to know you are a paid subscriber, eligible for the 2
day turn around?

Knowing what to search is always the key, I think I searched for "mdi mouse
events". From a quick test, I knew this didn't occur when mdi wasn't
involed. This only returned 53 hits, the first page of results led to the
answer.

Greg
 
S

StriderBob

I totally agree, the library here has almost all the books on VB.Net
published and I always print out the help pages as used, index and save
them, so they now fill a whole shelf.
Your comment about registering may prove beneficial but let me quote the
very latest msdn Subscriptions, Getting Started Guide, received last week
(My sub gets renewed in August).

"MSDN now includes managed newsgroup support for all Universal, Enterprise,
Professional and Operating System Subscribers. MSDN Subscribers can post
unlimited .NET product and tchnology questions to over 230 Microsoft public
newsgroups and receive a guaranteed response from Microsoft Support
Professionals within two business days.

http://msdn.microsoft.com/newsgroups/managed

Also, see your local MSDN website for details of other newsgroups in your
locality and language."

Where does it say you have to register anywhere for anything?

My Point is this. COMMUNICATIONS would be helpful, MS is a big business and
yet as you pointed out there are some 600 queries regarding mouse events and
god alone knows how much soul searching went on before they were ever
promulgated.Why cannot MS simply post an addendum in the mouse events part
of the Help Library which is updated regularly. Dont use this event in mdi
forms.!!!

How much msdn time is wasted answering repeat requests for information
concerning problems which are not going to be fixed until the next release,
if then?

Back in 1981 I bought Multiplan for the Apple llE, It was an early Microsoft
product and had the best manual I've ever seen for any product ever. For
twenty plus years I kept that manual and the 5.5" disks as an example of how
to write a manual and teach people to use a product. What happened??

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top