Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Integral Type Expected

Status
Not open for further replies.

JurkMonkey

Programmer
Nov 23, 2004
1,731
CA
So switch statements make me mad sometimes.

It won't let me switch a GUI Component, not even its name.

I want to say:

switch(tabControl1.SelectedTab)
{
case tabPage1:
case tabPage2:
...
}

but it always looks for an int, char, byte, blah blah.

Does anyone have a good solution to this? I always end up hacking around it and now I'm finally tired of it.

:)
 
Here's a hack for you:

I have an enum MyView { View1, View2, View3 }

then I have a Property

public MyView CurrentView
{
get
{
return (MyView) tabControl1.SelectedTab.Tag;
}
}

I set the enum value in the tag.

And if VisualStudio eats my code one more time, I swear....
 
does this work?
string sTest=tabControl1.SelectedTab.Name.ToString().Trim();

switch(sTest)
{
case 'tabPage1':// it may be "tabPage1" ,just play around


case 'tabPage2':
...
}

 
yeah, that works too. I've been doing that for quite some time now. I just hate hard coding names and values.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top