[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1067
  • Last Modified:

Skip Combobox SelectedIndexChanged Event when form is loading

I have events I call when someone selects a new value in a combobox.
When the form loads these events proceed.
In VB 6, in order to skip the event I used to put
If me.visible then
run the event
end if
This does not work in VB 2008.
How do I make the program skip the event when the form is loaded?
Thanks
0
Sheritlw
Asked:
Sheritlw
1 Solution
 
Wayne Taylor (webtubbs)Commented:
The standard method of ignoring control's event on form load is to use a Form level boolean variable, as shown in the below example.

Wayne
Public Class Form1
 
    Private Loaded As Boolean = False
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        Dim arr As New ArrayList
        For i As Integer = 1 To 20
            arr.Add(i)
        Next
 
        ComboBox1.DataSource = arr
 
        Loaded = True
 
    End Sub
 
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If Loaded Then
            MsgBox(ComboBox1.SelectedIndex)
        End If
    End Sub
 
End Class

Open in new window

0
 
SheritlwAuthor Commented:
Thanks, that works great!
0
 
käµfm³d 👽Commented:
Or you could add the handler for the combo box in the Form_Load instead of through the designer:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
    Dim arr As New ArrayList
    For i As Integer = 1 To 20
        arr.Add(i)
    Next
 
    ComboBox1.DataSource = arr
 
    AddHandler ComboBox1.SelectedIndexChanged, AddressOf(ComboBox1_SelectedIndexChanged)
 
End Sub

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now