Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
80
Showing Context Menu on a Particular BandHeader
posted

Hi All,

When i right click on a particular band header in an ultragrid ContextMenu should be visible,

on the other band headers it should not be visible.I have assigned keys to the bands during design time.

Am getting the  UIElement where user has clicked on the grid  from the following code

Point curPos = ultraGridSurvey.PointToClient(Cursor.Position);
UIElement mouseUIElement = ultraGridSurvey.DisplayLayout.UIElement.ElementFromPoint(curPos);

At runtime how can i find out whether the user has clicked on a Particular Band or a Band Header.

Could any one of u help me on this.

Thanks,

Pavana

 

  • 469350
    Verified Answer
    Offline posted

    Hi Pavana,

        Try something like this:


            private void ultraGrid1_MouseUp(object sender, MouseEventArgs e)
            {
                // Get the grid.
                UltraGrid grid = sender as UltraGrid;

                // Get the element. We could use ElementFromPoint, but this is easier.
                UIElement element = grid.DisplayLayout.UIElement.LastElementEntered;

                // See if the element is already a HeaderUIElement
                HeaderUIElement headerElement = element as HeaderUIElement;

                // If it's not a HeaderUIElement, see if one of it's ancestors is.
                if (headerElement == null)
                {
                    headerElement = element.GetAncestor(typeof(HeaderUIElement)) as HeaderUIElement;               
                }

                // No HeaderUIElement found, exit.
                if (headerElement == null)
                    return;

                // If there's a column, then this is a column header, not a band header, so exit.
                if (headerElement.Header.Column != null)
                    return;

                // Found a band header.
                Debug.WriteLine(headerElement.Header.Band.Key, "Band Header Clicked");
            }