Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9161863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:04:22+00:00 2026-06-17T14:04:22+00:00

I have this code behind a winforms which simply has a listbox as its

  • 0

I have this code behind a winforms which simply has a listbox as its only control:

Imports System.Windows.Forms
Public Class Form1

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        ListBoxX.Items.Add("hello")
        ListBoxX.Items.Add("world")
        ListBoxX.Items.Add("foo")
        ListBoxX.Items.Add("bar")

    End Sub

    Private Sub ListBoxX_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBoxX.SelectedIndexChanged
        MessageBox.Show("change registered")
    End Sub

    Private Sub ListBoxX_SelectedValueChanged(sender As Object, e As System.EventArgs) Handles ListBoxX.SelectedValueChanged
        MessageBox.Show("change registered X")
    End Sub
End Class

If “hello” is selected and I then click on “hello” then the message box appears – surely if I’m clicking on the same item then the SelectedIndex has not changed – so why is this event firing? How do I ensure it only fires when the index changes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:04:24+00:00Added an answer on June 17, 2026 at 2:04 pm

    Check inside the event if it is the same item as selected before,

    Save the last selected item each on click.

    Private Sub ListBoxX_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBoxX.SelectedIndexChanged
        if Not LastItem = ListBoxX.SelectedItem Then
            MessageBox.Show("change registered")
            LastItem = ListBoxX.SelectedItem 
        end if
    End Sub
    

    It’s been a while since I coded in VB, so I hope this code is OK.

    I assume that the event will always fires, no matter which item is selected.

    Another solution is to override the ListBox User Control, but I think you don;t need that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code in my code behind. using System; using System.Collections.Generic; using System.Linq;
In code-behind of an ASP.NET page I have this method: public string TestFunc() {
I have this code : void Main() { System.Timers.Timer t = new System.Timers.Timer (1000);
I have this code: ie1.link(:text, /Exception:/) It is producing an error message which I
I have this code in my code-behind file of my View: private string GetSelectedSchoolclassCode()
In a normal user control, we have .cs.ascx (code-behind) to assign the namespace we
Currently I have a Winforms app which relies on transpareny effects. However this is
I'm just couris about whats happning behind the scenes. I have this code and
I have this code in my ASP.NET code-behind file: Response.Write(<someting>) But it doesn't work.
Well i have this code in my code behind Public Shared ReadOnly UsernameProperty As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.