Click here to Skip to main content
15,894,896 members
Home / Discussions / C#
   

C#

 
QuestionMonitor letter Drive (D:) Pin
picasso211-Jan-07 18:15
picasso211-Jan-07 18:15 
AnswerRe: Monitor letter Drive (D:) Pin
stancrm11-Jan-07 19:53
stancrm11-Jan-07 19:53 
AnswerRe: Monitor letter Drive (D:) Pin
Nader Elshehabi11-Jan-07 21:37
Nader Elshehabi11-Jan-07 21:37 
QuestionAccessing Image from MS Access. [modified] Pin
Shaurya_Rastogi11-Jan-07 18:09
Shaurya_Rastogi11-Jan-07 18:09 
QuestionDataGrid Pin
swjam11-Jan-07 17:57
swjam11-Jan-07 17:57 
AnswerRe: DataGrid Pin
Nader Elshehabi11-Jan-07 21:48
Nader Elshehabi11-Jan-07 21:48 
Questionerror in storage.InsertRecords [modified] Pin
tahreen shah11-Jan-07 17:11
tahreen shah11-Jan-07 17:11 
QuestionWhen is a DropDownItem not a DropDownItem? [modified] Pin
JoeRip11-Jan-07 16:55
JoeRip11-Jan-07 16:55 
In my Windows.Forms app, I have a menu. That menu contains six menu items.

When the menu drops, I check a flag to see if the items in that menu should be disabled.

Here is the code:

private void miImport_DropDownOpening(object sender, EventArgs e)<br />
{<br />
foreach (ToolStripDropDownItem item in miImport.DropDownItems) item.Enabled = fMyFlag;<br />
}


This code executes flawlessly, disabling all the menu items when the flag is false.

However, once I add a separator bar between the items, this code throws the following exception:

Unable to cast object of type 'System.Windows.Forms.ToolStripSeparator' to type 'System.Windows.Forms.ToolStripDropDownItem'.

Can it possibly be true that the collection MenuItem.DropDownItems contains objects of different types? Isn't that verboten?

More importantly, why on earth would they do this? Why would any item they allow you to insert in the DropDownItem list not be treated as a DropDownItem?

This makes me pretty mad, as I'll have to write much longer code to individually disable these items.

Or am I missing something? Should I not be using "ToolStripDropDownItem" in my foreach loop?

Grr. I removed the item.Enabled = value line, and it still throws the exception. An empty foreach loop should NEVER throw an exception. If it's not an "each", why the hell is it being enumerated?


-- modified at 23:18 Thursday 11th January, 2007
AnswerRe: When is a DropDownItem not a DropDownItem? Pin
JoeRip11-Jan-07 17:29
JoeRip11-Jan-07 17:29 
AnswerRe: When is a DropDownItem not a DropDownItem? Pin
ChandruIT11-Jan-07 17:37
ChandruIT11-Jan-07 17:37 
GeneralRe: When is a DropDownItem not a DropDownItem? Pin
JoeRip11-Jan-07 18:25
JoeRip11-Jan-07 18:25 
QuestionPreview Type Window (Form) Pin
Nooie11-Jan-07 15:19
Nooie11-Jan-07 15:19 
Questiontopic for final year proj inj c# Pin
Mri1a11-Jan-07 12:56
Mri1a11-Jan-07 12:56 
AnswerRe: topic for final year proj inj c# Pin
Not Active11-Jan-07 14:42
mentorNot Active11-Jan-07 14:42 
GeneralRe: topic for final year proj inj c# Pin
Stephen Hewitt11-Jan-07 15:45
Stephen Hewitt11-Jan-07 15:45 
GeneralRe: topic for final year proj inj c# Pin
J4amieC11-Jan-07 22:28
J4amieC11-Jan-07 22:28 
GeneralRe: topic for final year proj inj c# Pin
Adam Crawford12-Jan-07 4:45
Adam Crawford12-Jan-07 4:45 
GeneralRe: topic for final year proj inj c# Pin
Stephen Hewitt14-Jan-07 12:11
Stephen Hewitt14-Jan-07 12:11 
GeneralRe: topic for final year proj inj c# Pin
ednrgc12-Jan-07 4:04
ednrgc12-Jan-07 4:04 
AnswerRe: topic for final year proj inj c# Pin
Christian Graus11-Jan-07 16:30
protectorChristian Graus11-Jan-07 16:30 
GeneralRe: topic for final year proj inj c# Pin
Stephen Hewitt11-Jan-07 17:19
Stephen Hewitt11-Jan-07 17:19 
GeneralRe: topic for final year proj inj c# Pin
Christian Graus11-Jan-07 17:45
protectorChristian Graus11-Jan-07 17:45 
GeneralRe: topic for final year proj inj c# Pin
ednrgc12-Jan-07 4:06
ednrgc12-Jan-07 4:06 
GeneralRe: topic for final year proj inj c# Pin
ednrgc12-Jan-07 4:08
ednrgc12-Jan-07 4:08 
AnswerRe: topic for final year proj inj c# Pin
PavanPareta11-Jan-07 17:48
PavanPareta11-Jan-07 17:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.