Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Elegant Ribbon Tech Support » How to get a right click on an item in a gallery? Collapse All
Subject Author Date
patrick fritzsch Feb 8, 2011 - 6:18 AM

II use a gallery inside a ribbon.


How can i retrieve a right click on a gallery item and display my own right click popup dialog and not the "Show quick Access - Minimize Ribbon" popup dialog?


i use currently Elegant Ribbon 3.7 source edition.

Technical Support Feb 9, 2011 - 4:32 AM

This functionality is not supported. However, we’ve prepared a code snippet that illustrates the way to extend a standard context menu for a Gallery in the Ribbon control.

     Form1() // Form1 constructor
     {
            Elegant.Ui.Button b1 = new Elegant.Ui.Button();
	    b1.Text = "button1";
            Elegant.Ui.Button b2 = new Elegant.Ui.Button();
            b2.Text = "button2";
            Elegant.Ui.Button b3 = new Elegant.Ui.Button();
            b3.Text = "button3";
            Elegant.Ui.Button b4 = new Elegant.Ui.Button();
            b4.Text = "button4";
            Elegant.Ui.Button b5 = new Elegant.Ui.Button();
            b5.Text = "button5";

            Elegant.Ui.ContextMenu cm = new Elegant.Ui.ContextMenu();
            cm.BeginInit();
            cm.Items.AddRange(
                new System.Windows.Forms.Control[]
                    {
                        b1, b2, b3, b4, new Elegant.Ui.Separator(), b5
	           	});
            cm.EndInit();

	    gallery1.ContextPopupMenu = cm;
            Elegant.Ui.ContextMenu.RegisterControlContextMenu(gallery1.Popup.Child, cm);

            cm.Showing += new EventHandler(cm_Showing);
	}

        void cm_Showing(object sender, EventArgs e)
        {
            currentGalleryItem = null;

            Elegant.Ui.Control control = Elegant.Ui.Control.FromPoint(System.Windows.Forms.Cursor.Position) as Control;
            if (control == null)
                return;

            FieldInfo fieldInfo = control.GetType().GetField("GalleryItem", BindingFlags.Instance | BindingFlags.Public);
            if (fieldInfo == null)
                return;

            currentGalleryItem = fieldInfo.GetValue(control); 
        }

	private object currentGalleryItem; // this field will store the gallery item for which context menu is currently shown.
You should use the currentGalleryItem field value to determine the current gallery item associated with the context menu.

patrick fritzsch Feb 9, 2011 - 11:57 AM

Thank you, this is working.