Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Me.lstFirstNames.Items.Add("Gary")
Me.lstFirstNames.Items.Add("Sam")
Control.DataBinding.Add( _
"ControlPropertyToBind", Source, "SourceProperty")
' Choose a ListBox to be the master and bind all remaining ListBoxes to the master SelectedIndex property.
Me.lstAges.DataBindings.Add( _
"SelectedIndex", Me.lstFirstNames, "SelectedIndex")
Me.lstCities.DataBindings.Add( _
"SelectedIndex", Me.lstFirstNames, "SelectedIndex")
Me.lstStates.DataBindings.Add( _
"SelectedIndex", Me.lstFirstNames, "SelectedIndex")
Me.lstLastNames.DataBindings.Add( _
"SelectedIndex", Me.lstFirstNames, "SelectedIndex")
' Add bindings for the TopIndex property also.
Me.lstAges.DataBindings.Add( _
"TopIndex", Me.lstFirstNames, "TopIndex")
Me.lstCities.DataBindings.Add( _
"TopIndex", Me.lstFirstNames, "TopIndex")
Me.lstStates.DataBindings.Add( _
"TopIndex", Me.lstFirstNames, "TopIndex")
Me.lstLastNames.DataBindings.Add( _
"TopIndex", Me.lstFirstNames, "TopIndex")
' Add handler for all ListBoxes but the master ListBox.
AddHandler lstAges.SelectedIndexChanged, _
AddressOf IndexChanged
AddHandler lstCities.SelectedIndexChanged, _
AddressOf IndexChanged
AddHandler lstStates.SelectedIndexChanged, _
AddressOf IndexChanged
AddHandler lstLastNames.SelectedIndexChanged, _
AddressOf IndexChanged
Private Sub IndexChanged( _
ByVal sender As Object, ByVal e As System.EventArgs)
' Static variables are only initialized once.
Static staticSelectedIndex As Integer = -1
' MsgBox allows us to see intermediate results.
' Note that Sender is CTyped to a couple different types.
MsgBox("Static: " & staticSelectedIndex.ToString & vbNewLine & "Sender: " & CType(sender, Control).Name & vbNewLine & "Index: " & CType(sender, ListBox).SelectedIndex.ToString, MsgBoxStyle.Information)
' Set master ListBox SelectedIndex once per change.
If CType(sender, ListBox).SelectedIndex <> _
staticSelectedIndex Then
staticSelectedIndex = _
CType(sender, ListBox).SelectedIndex
Me.lstFirstNames.SelectedIndex = _
staticSelectedIndex
End If
End Sub 'IndexChanged
Private Sub lstAges_SelectedIndexChanged( _
ByVal sender As Object, ByVal e As System.EventArgs) _
Handles lstAges.SelectedIndexChanged, _
lstCities.SelectedIndexChanged, _
lstLastNames.SelectedIndexChanged, _
lstStates.SelectedIndexChanged
' The code would be identical to the above method
' so I did not repeat any of it here.
End Sub 'lstAges_SelectedIndexChanged