cancel
Showing results for 
Search instead for 
Did you mean: 

ContextMenuStrip - testing associated image

SOLVED
Highlighted
Occasional Contributor

ContextMenuStrip - testing associated image

Hi

 

I have a ContextMenuStrip that contains items that consist of both image and text (see attached PNG).

 

The test needs to confirm whether the item in the menu is ticked or not and action accordingly. I have looked at the properties of the menu item and the most appropriate (checked) is set to false regardless of whether its ticked or not.

 

Anyone have any suggestions to how to test this?

 

I am aware that it is possible to get the state of certain pixels to see whether they are set or not, I would prefer a simpler more reliable method if anyone knows of one.

 

Many thanks

 

Peter Mitcham

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Occasional Contributor

Re: ContextMenuStrip - testing associated image

Yes, I have access to developers and have spoken with them since the first post.

 

The contextmenu contents when selected\deselected alter the visible structure of a grid. A hashtable is used to store the contents of the contextmenu and the hashtable is associated to the grid container object.

 

I have managed to find a solution (other than testing pixels, however, unfortunately it is also fairly complicated.)

 

Each Contextmenustrip content is derived from an associated hashtable, which in turn is populated from the current visible content within the associated grid (the contextmenu content when selected\deselected alters the visible structure of a grid)

 

The associated hashtable will only contain the currently selected contextmenustrip content but it will retain the original position within the menu.

 

An example of what i am saying is this

 

If the menu contains 4 items and only 3 are selected (items 1, 3, 4), the associated hashtable will contain the following.

 

item1

item3

item4

 

Even though 2 exists in the contextmenu, because it is not selected it does not appear in the associated hashtable.

 

The solution I have created enumerates through the hashtable checking if the item I need to select\deselect exists or not.

 

1) I  check the state of the hashtable prior to performing my action on the contextmenustrip ( the contextmenustrio does not need to be visible to do this).

2) Confirm the state and act accordingly (if its already selected, do nothing, otherwise select it)

3) Where the contextmenustrip has been updated then I validate the hashtable contents post selection.

 

View solution in original post

6 REPLIES 6
Highlighted
Community Hero

Re: ContextMenuStrip - testing associated image

Do you have access to the developers?

 

If the standard "checked" property is not being used, they must be using something custom. Much easier to ask them than guess at the other options. I had a similar thing with a tree view they had customised to propgate up and down the tree if an object in a middle node was checked. They also weren't using the "checked" property. In my case, they were using a value in the "ImageIndex" property.

Highlighted
Occasional Contributor

Re: ContextMenuStrip - testing associated image

Yes, I have access to developers and have spoken with them since the first post.

 

The contextmenu contents when selected\deselected alter the visible structure of a grid. A hashtable is used to store the contents of the contextmenu and the hashtable is associated to the grid container object.

 

I have managed to find a solution (other than testing pixels, however, unfortunately it is also fairly complicated.)

 

Each Contextmenustrip content is derived from an associated hashtable, which in turn is populated from the current visible content within the associated grid (the contextmenu content when selected\deselected alters the visible structure of a grid)

 

The associated hashtable will only contain the currently selected contextmenustrip content but it will retain the original position within the menu.

 

An example of what i am saying is this

 

If the menu contains 4 items and only 3 are selected (items 1, 3, 4), the associated hashtable will contain the following.

 

item1

item3

item4

 

Even though 2 exists in the contextmenu, because it is not selected it does not appear in the associated hashtable.

 

The solution I have created enumerates through the hashtable checking if the item I need to select\deselect exists or not.

 

1) I  check the state of the hashtable prior to performing my action on the contextmenustrip ( the contextmenustrio does not need to be visible to do this).

2) Confirm the state and act accordingly (if its already selected, do nothing, otherwise select it)

3) Where the contextmenustrip has been updated then I validate the hashtable contents post selection.

 

View solution in original post

Highlighted
Community Hero

Re: ContextMenuStrip - testing associated image

lol

 

Gotta love custom/non-standard use of controls!

Highlighted
Moderator

Re: ContextMenuStrip - testing associated image

If the developers are using images/bitmaps and not something fancy like custom painting, there probably is an easier way. According to this, custom item images are accessible via:

menuObj.Items.Item_2(index).Image

or if there're nested menus:

menuObj.Items.Item_2(index1).DropDownItems.Item_2(index2).Image

If an item does not have an image, the Image property is null.

 


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Occasional Contributor

Re: ContextMenuStrip - testing associated image

Hi Helen

 

Thank you very much for your suggestion, unfortunately neither option is usable.

 

menuObj.Items.Item_2(index).Image returns Null object

menuObj.Items.Item_2(index1).DropDownItems.Item_2(index2).Image returns a count of 0 on the dropdownitems.item

 

Many thanks

 

Peter Mitcham

Highlighted
Moderator

Re: ContextMenuStrip - testing associated image

I see. In that case, your approach is the way to go.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors