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

  • Home
  • SEARCH
  • 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 7762883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:31:24+00:00 2026-06-01T14:31:24+00:00

I am handling tab change in the WinForms TabControl’s Deselecting event. However, in some

  • 0

I am handling tab change in the WinForms TabControl’s Deselecting event. However, in some cases I am deleting the tab that I clicked on before I switch to it.

scenario

I have tab 1 and tab 2
currently I’m in tab 1
I click on tab 2
tab 1 Deselecting Event Removes Tab 2 from the tab collection
Crashes at OnPaint because it’s trying to go to a tab that no longer exists. (ArgumentOutOfRangeException). It crashes before it hits the Selecting Event.

I don’t want to see if the tabcount changed in deselecting because I only want to cancel if the tab I’m going to no longer exists.

Any help would be greatly appreciated.

    private void TabControl_Deselecting( object sender, TabControlCancelEventArgs ) {
       DoSomeWork();
    }

Assume that DoSomeWork deletes the Tab I clicked on. How can I find out if it did delete the tab I was intending to go to?

  • 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-01T14:31:26+00:00Added an answer on June 1, 2026 at 2:31 pm

    No repro. The scenario is strange but I can’t get it to crash. Do make sure you cancel the Deselect.

        private void tabControl1_Deselecting(object sender, TabControlCancelEventArgs e) {
            if (e.TabPageIndex == 0 && tabControl1.TabCount > 1) {
                tabControl1.TabPages[1].Dispose();
                e.Cancel = true;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for some best practices as far as handling csv and tab
I'm refactoring a WinForms (.NET 4) application that makes use of a TabControl to
Exception handling in php ... I have noticed some quirks that seem to make
I need to implement handling of redelivery of JMS messages in the application that
I was handling yet another KeyDown event in a user control when I wondered
Javascript jQuery event handling If on event (for example 'click') bound one function for
I know that for handling keyboard events in an input field you can use:
Assume that I have a class that exposes the following event: public event EventHandler
I am working on some PHP classes that can do some basic profiling, debugging,
This question follows this: handling to onchange event of AutoCompleteTextField in wicket I'm trying

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.