Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a search panel on my form with a textbox, a button and a couple of checkboxes for search options. There is also a tabcontrol that starts off hidden and a progressbar. On performing a search a new tabpage containing a listbox is added to the control, the results are displayed in the listbox and the control is made visible if it's the first tabpage. The idea being that the user can retain previous searches on separate tabs.

 

This all works perfectly.

 

The tabs are closed either individually or all together from a context menu associated with the tabcontrol. The code for the menu items is below.

 

   Private Sub tmiRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmiRemove.Click
       Dim CurrentTab As TabPage = Searches.SelectedTab
       Searches.TabPages.Remove(CurrentTab)
       If Searches.TabCount = 0 Then
           Searches.Visible = False
           SearchProgress.Value = 0
       End If
   End Sub

   Private Sub tmiRemoveAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmiRemoveAll.Click
       Searches.TabPages.Clear()
       Searches.Visible = False
       SearchProgress.Value = 0
   End Sub

 

If I left click a tab and then bring up the context menu and select either one of the above items then everything is fine. However, if I select one of the menu items without left clicking first, in other words after the code has added a new tab and that has focus or a tab has been removed and focus moves to the next one automatically, the above code still works and removes the correct tabs but after that the app' can no longer be shut down. Neither the close icon or the exit sub-routine work. The rest of the app' still functions normally.

 

Anyone have any clue?

I'm getting the hang of this now... No really I am!
Posted
I have had this problem before. I had to move all of my code for my tab from the load to the new constructor. After I did that it let me close the form. I was removing enabling and jacking with the tabs as the form was getting loaded. You are wanting to alter the tabs during run-time so I don't know if this will help you or not. But at least you know your not the only one that has gotten this bug. Hope this gives you some ideas and or fixes you issues.
Posted

I had this problem as well.

When removing the tabpage, you must set the focus to a different control, like a button:

...
Dim CurrentTab As TabPage = Searches.SelectedTab
butSomething.focus()
       Searches.TabPages.Remove(CurrentTab)
       If Searches.TabCount = 0 Then
...

Posted

Cheers for the suggestions guys. I tried Davehs first cos it was quicker and it seems to have solved the problem. The only thing though, is that in the second sub-routine I had to remove the pages individually rather than clearing all of them together for this to work.

 

Incase anyone else has this problem here is the revised code...

 

Private Sub tmiRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmiRemove.Click
       Dim CurrentTab As TabPage = Searches.SelectedTab
       SearchString.Focus()
       Searches.TabPages.Remove(CurrentTab)
       If Searches.TabCount = 0 Then
           Searches.Visible = False
           SearchProgress.Value = 0
       End If
   End Sub

   Private Sub tmiRemoveAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmiRemoveAll.Click
       Dim tp As TabPage
       For Each tp In Searches.TabPages
           SearchString.Focus()
           Searches.TabPages.Remove(tp)
       Next
       Searches.Visible = False
       SearchProgress.Value = 0
   End Sub

 

Cheers,

Andy!

I'm getting the hang of this now... No really I am!
  • 1 month later...
Posted

something to add...

 

Thanks for posting this problem and replies, it has saved me some trouble.

In my case I was trying to add a second tabPage and then delete the first one. I though that I could set the focus to a button in the tabPage just added, well... that's not the case. You need to set focus to something that is outside the whole tabControl.

If anybody has a clever answer to this behavior, it would be appreciated.

Good Luck,

ChrisCKX.

Posted

The REAL answer - Dispose tabpages first

 

Hi,

Here is what really needs to be done to solve this.

You need to Dispose() the tabpage before removing it from the control. That is the bug, somehow the tabpage doesn't get cleaned up and that causes the app not to shut down.

 

so, suppose you have a TabPage myTabpage already in TabControl, in order to safely remove it, you need to do:

 

myTabpage.Dispose();

myTabControl.Remove(myTabpage);

 

you could also get a reference to the page thourgh the

DataTab.TabPages[] property and call dispose on that reference, same result.

 

Hope this saves someone some pain.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...