Click here to Skip to main content
15,940,550 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i have a dialogue box with many tabs. i want it to open with a particular tabcontrol. how can i do it?
Posted

1 solution

Use the TabControl.SelectedTab[^] property - you can set it in your Load event, or as part of your constructor.



"yeh i know i m saying the same but not in a proper way.
i wanna open "view" dialogue with a specified tab n its not the current instance.
if i code this view v1 = new view then does view become the current instance?"



view never becomes an instance - it is the structure of the class.
If you execute the code:
view v1 = new view();
Then a number of things happen:
1) A local variable called v1 is created, which can refer to items of the view class.
2) A new instance of a view is created
3) The constructor for view is called, and this becomes a reference to the new instance just created. Whenever you code in the view class and it uses this either explicitly with
this.myProperty = "Hello";
or implicitly with
myProperty = "Hello";
it refers to the instance.
4) vi is assigned the value of the instance, for you to do whatever you need to outside the view class.

In your case, you probably want to do something along the lines of:
view v1 = new view();
v1.ActiveTab = "Tab Text";
v1.ShowDialog();
Only you will have to write the property "ActiveTab" in your View Class to select the active tab!



"ok its done.
i code this"

View v2 = new View();
v2.Show();
v2.vtab.SelectedTab = v2.vtab.TabPages[1];
v2.vtab.Show();



Please, for your own sake, don't do that. Instead set up a public int property in the View class which selects that tab page:
public int SelectPage
   {
   get { return vtab.SelectedIndex; }
   set { vtab.SelectedTab = vtab.TabPages[value]; }
   }
Do not make form controls public! If you do, you tie the two forms together - you can't change how one works internally without considering the effects on the other. This is against the principles of OOP!
 
Share this answer
 
v3
Comments
Sweety Khan 20-Jun-11 3:55am    
they r using "this" means already opened dialogue box?
OriginalGriff 20-Jun-11 4:09am    
I think you need to read up on C# basics: "this" refers to the current instance of the class - in this case it is the form - but it doesn't have to be "open" or anything else. You can use "this" in the constructor, or any other method. They are using it for illustration - normally "this" is implicit in the statement whenever you access class fields, properties or methods from class code.
Sweety Khan 20-Jun-11 4:30am    
yeh i know i m saying the same but not in a proper way.
i wanna open "view" dialogue with a specified tab n its not the current instance.
if i code this view v1 = new view then does view become the current instance?
Sweety Khan 20-Jun-11 12:40pm    
ok its done.
i code this
View v2 = new View();
v2.Show();
v2.vtab.SelectedTab = v2.vtab.TabPages[1];
v2.vtab.Show();
OriginalGriff 20-Jun-11 15:11pm    
Answer updated

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