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 694709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:53:04+00:00 2026-05-14T02:53:04+00:00

Is it possible to cancel the SelectedIndexChange event for a listbox on a winforms

  • 0

Is it possible to cancel the SelectedIndexChange event for a listbox on a winforms application? This seems like such a logical thing to have that I must be overlooking some easy feature. Basically, I have been popping up a message box asking if the user really wants to move to another item, as this will change the UI and I don’t want their changes to be lost. I’d like to be able to cancel the event in case the user has not saved what they are working on. Is there a better way of doing this?

  • 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-05-14T02:53:04+00:00Added an answer on May 14, 2026 at 2:53 am

    You cannot cancel it.

    What I did just a couple of days ago was to have a variable with the latest selected index. Then when the event fires, you ask the user if he wants to save, this is done in the eventhandler. If the user selected “Cancel” you change the id again.

    The problem is that this will make the event fire once again. So what i’ve used is a bool just saying “Inhibit”. And at the top of the eventhandler I have:

    if(Inhibit)
       return;
    

    Then below this where you ask the question you do something like this:

    DialogResult result = MessageBox.Show("yadadadad", yadada cancel etc);
    if(result == DialogResult.Cancel){
       Inhibit = true; //Make sure that the event does not fire again
       list.SelectedIndex = LastSelectedIndex; //your variable
       Inhibit = false; //Enable the event again
    }
    LastSelectedIndex = list.SelectedIndex; // Save latest index.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to cancel the Session Lock Event? I have this code to
Is it possible that using jQuery, I cancel/abort an Ajax request that I have
I have read that its not possible to cancel an active ajax request, however
Is it possible to cancel a linq2sql query? Like if I have built a
I have an activity that fires a notification is it possible to cancel that
Is it possible to cancel an event from within the onKey method. I only
I am wondering if it is possible to have the Cancel button on my
Is it possible to cancel an Azure table query? We have cases where we
How it is possible to cancel/reject applied ViewCriteria, lets say I have view criteria
Is it possible to cancel the browser close window event? Or at least add

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.