Hi I need help with switch statement. I am getting an error "a value of an integral type is expected". and this is the code:
private
void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e){
switch (toolStrip1){
case toolStripNew:newToolStripMenuItem_Click(sender, e );
break; case toolStripOpen:openToolStripMenuItem_Click(sender, e );
break;}
}

ToolStrip problem
Neotech
Your problem is the folloiwng if you want to use Switch you can only use only Integral types
The following table shows the list integral types
Type
sbyte
byte
char
short
ushort
int
uint
long
ulong
for more info go to http://msdn2.microsoft.com/en-us/library/exx3b86w.aspx
so you should modifay your code us
private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
switch
(e.ClickedItem.Name){
case "toolStripNew":
newToolStripMenuItem_Click(sender, e );
break; case "toolStripOpen":openToolStripMenuItem_Click(sender, e );
break;}
}
Cheers
Mamush
Ryan_Willardryan
PeterVrenken
Multiple problems.
1: switch can only be used with simple types like int and string. You'll have to use if/else/else/etc.
2: you appear to be testing the ToolStrip itself to see whether it is one of its buttons. You need to test e.ClickedItem.
3: you are passing an object of type ToolStripItemClickedEventArgs to methods which expect EventArgs; while this will work, it's meaningless and may cause confusion.
In summary, then:
if(e.ItemClicked == toolStripNew)
newToolStripMenuItem_Click(toolStripNew, new EventArgs());
else if(e.ItemClicked == toolStripOpen)
openToolStripMenuItem_Click(toolStripOpen, new EventArgs());
should work for you.