Forum Discussion

PeterMitcham's avatar
PeterMitcham
Occasional Contributor
9 years ago
Solved

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

 

 

  • PeterMitcham's avatar
    PeterMitcham
    9 years ago

    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.

     

6 Replies

  • 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.

    • PeterMitcham's avatar
      PeterMitcham
      Occasional Contributor

      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.

       

      • Colin_McCrae's avatar
        Colin_McCrae
        Community Hero

        lol

         

        Gotta love custom/non-standard use of controls!