473,800 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ToolStripDropDo wnMenu and SourceControl ??

Hello all,

I have dynamic controls all associated with a single ContextMenuStri p. For
each menu item I have click event method. For each event I have cast sender
to ToolStripMenuIt em to ContextMenuStip to use SourceControl to get the
control that initiated the event.

This all works well if the the menu items are one level deep on the
contextmenustri p control, but if I create a sub menu item doing the above
logic does not work.

First of all it gives a cast error of
"Unable to cast object of type "System...ToolS tripDropDownMen u" to
"System...Conte xtMenuStrip." So in the case of a sub menu I changed the cast
to ToolStripDropDo wnMenu.

ToolStripMenuIt em TlStrip = (ToolStripMenuI tem)sender;
ToolStripDropDo wnMenu temp = (ToolStripDropD ownMenu)TlStrip .Owner;
TlStrip = (ToolStripMenuI tem)temp.OwnerI tem;
ContextMenuStri p Mnu = (ContextMenuStr ip)TlStrip.Owne r;

Using above code Mnu.SourceContr ol is always null.

What am I doing wrong?

--
Best Regards

"Failure is the opportunity to begin again more intelligently" – Henry Ford
Jun 27 '08 #1
4 6135
Its difficult to know when there are no responses wheather my question is not
detailed enough, not a common problem so no one is familiar with it to
answer, or just a dumb question (I have had a few). :)

For now going with need clarification. :)

I have a context menu strip as follows:
TestA
TestB - SubTestB

if I click on TestA Everything works fine. If I click on SubTestB the below
call to GetCtrl returns true but MyIcon is null.

Code Snippets:
///////////////////////////////////////////////////////////////
private bool GetCtrl(ToolStr ipMenuItem sender, ref MyDefIcon MyIcon)
{
bool bGood = false;
try
{
if (sender != null)
{
ContextMenuStri p Mnu = (ContextMenuStr ip)sender.Owner ;

if (Mnu != null)
{
MyIcon = (MyDefIcon)Mnu. SourceControl;
bGood = true;
}
}
}
catch (Exception ex)
{
MessageBox.Show (ex.Message);
}

return (bGood);
}
///////////////////////////////////////////////////////////////
private void TestAToolStripM enuItem_Click(o bject sender, EventArgs e)
{
MyDefIcon MyIcon = null;
if(GetCtrl((Too lStripMenuItem) sender, ref MyIcon ))
{
if (MyIcon != null)
{
// do command
}
}
}
}
///////////////////////////////////////////////////////////////
private void SubTestBToolStr ipMenuItem_Clic k(object sender,
EventArgs e)
{
ToolStripMenuIt em TlStrip = (ToolStripMenuI tem)sender;
ToolStripDropDo wnMenu temp =
(ToolStripDropD ownMenu)TlStrip .Owner;

MyDefIcon MyIcon = null;
if(GetCtrl((Too lStripMenuItem) temp.OwnerItem, ref MyIcon ))
{
if (MyIcon != null)
{
// do command
}
}
}
}


Please give advice or direction.

--
Best Regards

"Failure is the opportunity to begin again more intelligently" – Henry Ford

Jun 27 '08 #2
On Mon, 28 Apr 2008 12:52:00 -0700, David
<Da***@discussi ons.microsoft.c omwrote:
Its difficult to know when there are no responses wheather my question
is not
detailed enough, not a common problem so no one is familiar with it to
answer, or just a dumb question (I have had a few). :)
How about option D: three hours is way too early to start getting worried
about whether anyone's going to answer your question.

Anyway, I seem to be able to reproduce the issue you're seeing. And I'd
agree that it seems to be wrong. Upon finding the top-level
ContextMenuStri p instance in which your menu item is contained, the
SourceControl property should, IMHO, _always_ tell you the name of the
control used to show the menu. But for me, just as you said, I find the
property is set to null when handling the Click event of a menu item
that's not a top-level item.

Seems like a bug to me. I suppose it might not be, but I'd have to see a
really good explanation for the behavior for me to believe that. You may
at this point simply need to consider finding a work-around and report the
bug to Microsoft in the hopes of getting it fixed.

Pete
Jun 27 '08 #3
By the way, a quick Google search turned up these:

What looks like an earlier, worse manifestation of the bug you found:
http://connect.microsoft.com/VisualS...edbackID=96476

A newer bug report describing the specific behavior you're running into:
https://connect.microsoft.com/Visual...dbackID=282496

Looks like sloppy work by whoever fixed the first bug.

Both articles describe what seems to me to be a reasonable workaround
(handle the Opening event for the context menu, and get the SourceControl
value then, at which point it's apparently still correct, saving it for
later use in the Click handler for the item).

Pete
Jun 27 '08 #4
Thanks for the information Peter, and sorry for my impatience. :)

--
Best Regards

"Failure is the opportunity to begin again more intelligently" – Henry Ford
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1667
by: MD | last post by:
I have a ContextMenu that is assigned to 3 RichTextBox's (i.e., if you right-click on any of the 3 RichTextBox's, you get the same ContextMenu). My ContextMenu has 2 items, each of which have their own click event handlers. When I click on any of the options in the ContextMenu, I want to know which RichTextBox the ContextMenu is currently opened in, so I thought I could check the SourceControl property. The problem is, the property is...
1
1207
by: Jose | last post by:
Hi, Our small company is growing quickly, and we need a source control and build tool for all our c# .net code. For build tool, i was thinking Nant. For source control, i was thinking perforce (for Win). Any home runs out there?
8
10103
by: Dennis C. Drumm | last post by:
Is there a way to modify the standard context menu shown when someone right clicks in a windows text box and that would work for all open windows applications? The standard context menu for a text box has 6 items, undo, cut, copy, paste, delete and select all. I would like to add one additional paste menu that opens a new sub menu with several optional text items that could be pasted. The items would be populated by my program but...
1
2848
by: Wael_Bakr | last post by:
Hi I used to use one contextmenu for many controls when popup I had to get sourcecontrol property of sender to know owner control using 2005 beta contextmenustrip I don't find a similar property can any body help thanks in advance
3
1906
by: Andy | last post by:
Hi I need a source/version control system for my different projects. I know I could use SourceSafe 2005 when it comes, but I've spent a lot of money on MSDN pro and need a free/cheap alternative. Any suggestions? /A.
3
1629
by: Bad_Kid | last post by:
How can solution (asp.net web page) be removed from the SourceControl? Do I have to make a new "blank solution" and add in it all projects one by one?
1
6342
by: goRide | last post by:
Hi, I'm looking of a way (preferred - a ready class or dll) to customize the context menu. many application has more controls inside the context menu (like textbox, sliders, checkbox, panel etc'). is there a way making this without writing my own context menu (meaning, popup form or something) ? Please don't post commercial products to this topic thanks.
22
7444
by: MarkusR | last post by:
I am currently using StarTeam for my source control. (Will eventual switch to whatever the latest Visual Source Safe is going to be called). With debug, installers, deploy and everything the project directory structure is a mess of files and directories What files should be in source control (All final builds willbe done on anothe machine)?
13
2859
by: PetterL | last post by:
I writing a program where I read menu items from a file. But I have problem when I click an menu item i want it to mark that one as checked but I cant access the menu object of that item to see witch object was selected. This is the sub procedure that read the items from an Array and create the menutitem. The array hold more information to use in program when one of the items is selected. Dim finisharray(,) As String ' is set up...
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.