Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello

how can I navigate to the previous TabPage in TabControl ( not the first one ) after I remove a tabpage
Posted
Comments
Sergey Alexandrovich Kryukov 18-Jan-13 17:48pm    
What is TapControl? To tap in some window? or a door? Knock-knock... Nice idea, by the way. :-)
—SA
Alhoot2004 19-Jan-13 10:40am    
hi Sergey
I mean System.Windows.Forms.tabControl

and my question is about showing the previous tabpage(e.g: with index = 2 , if we were in 3'd tabpage before removing it) , I also remove each bage using a closebutton component which is a member of a usercontrol that added to a tabpage at creation ,

any shortcuts?
thanks
Sergey Alexandrovich Kryukov 19-Jan-13 17:51pm    
I got it; it was just a little fun.
I gave you a complete answer to your question. These two properties I referenced is all you need. Did you get it?
Are you going to accept it formally (green button)?
—SA
Alhoot2004 19-Jan-13 19:27pm    
I know that I'm talking with a clever man (Andalso I see your name in the top experts list) , but unfortunately my English is the main problem here , and I think that if you catch the point it well be a nice thing to think about. honestly, if I missed MSDN as a reference thats mean that I'm in big trouble..

sergey ,
the point is (with Mathematical ENGLISH ) :
myForm --> in its members
system.windows.forms.tabcontrol called TC1
TC1 ==> have just one tabpage lets call it tp(0) , this is the only one user cannot remove , tp(0) contains a datagridview _ doubleclick on a row on it fire adding tabpages in TC1 , lets call it tp(i) : where i>0

each tp(i) contains a panel wich is a system.windows.forms.usercontrol - call it - UC

in a UC , I create an "X" button (Component Inherits Button) to remove tp(i)
if User click this (each) button
my question is:

the i'th "X" button remove tp(i)
but after tp(i) is removed the selected tabpage is tp(0) , what i need is to set::

TC1.SelectedTab = tp(i-1)

thanks a million
Sergey Alexandrovich Kryukov 19-Jan-13 20:11pm    
Apparently, you will need to select the tab of your choice. You need to be careful of numbering, as when you remove one page, the numbering will be shifted (of course, not if you want the previous page (before the deleted one), and such page existed). Also, you need to take care of the situation when no pages left.

It might be simpler of you chose the page to select before removal. It will be easier if you use SelectedTab, not SelectedIndex. SelectedTab require reference to the page you choose to select after deletion; and the reference cannot be "shifted" :-)

That's all what is involved. Everything else is per your design.

—SA

1 solution

Right. Of course you should take care about it. But, as I say, it really depends on what class are you talking about.

It could be:
http://msdn.microsoft.com/en-us/library/system.windows.forms.tabcontrol.selectedindex.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.tabcontrol.selectedtab.aspx[^].

Or, it could be this one:
http://msdn.microsoft.com/en-us/library/system.windows.controls.tabcontrol.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.selector.selecteditem.aspx[^].

Or, it could be some other library.

You should really always tag the library or application type you are using. Better yet, you should read documentation by yourself. Looking at your question, I'm afraid to imagine what else will you need to ask working is this ineffective style. Did you ever ask yourself how many properties and types are there in FCL?!

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900