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
335
How to capture Click Event for a Group Header and re-direct to a Column Header
posted

I have a grid that shows a customer code, name, and 12 months of sales data.  For each month, I show Cases and Sales $.  The 2 columns for each month are vertically stacked under a group header caption which identifies the month (Jan, Feb, Mar, etc., column headers are hidden), and there are also 2 unbound columns vertically stacked in their own group to act as line labels within the row indicating "Cases" or "Sales".

I have a radio button elsewhere on the form where the user would choose Cases or Sales $, so that when they click on the Jan Group, they can control which of the 2 types of data they want the sort to occur on. 

I know that If I show the column headers, then the user could simply click to sort the column header within the group corresponding to the datacolumn that they want to sort, but this would add too much bulk to the grid header - my example above describes 2 vertically stacked columns per group, but my user can also ask to see 3 or 4 or 5 data columns per group.

1) How can I capture the click event on the group header so that I know which group header was clicked?  I am struggling with unraveling the UIElement that I have captured (using ElementFromPoint) in the mousedown, trying to resolve that to a group header.

2) I am thinking that if I knew the group header that was clicked, I could code the sorting of columns using the sortedcolumns collection.  But is there a simpler way I can pass the group header click on to the column header that I want the intended sort to act on?

 

  • 469350
    Suggested Answer
    Offline posted

    You can do something like this:



            private void ultraGrid1_MouseDown(object sender, MouseEventArgs e)
            {
                UltraGrid grid = (UltraGrid)sender;
                UIElement element = grid.DisplayLayout.UIElement.LastElementEntered;
               
                // See if the element is a HeaderUIElement. This will probably never happen
                // because the header element is filled with a TexUIElement, but it's best to
                // cover all the bases.
                HeaderUIElement headerElement = element as HeaderUIElement;

                if (headerElement == null)
                {
                    // See if the element has a HeaderUIElement in it's parent chain.
                    headerElement = element.GetAncestor(typeof(HeaderUIElement)) as HeaderUIElement;
                }

                // We failed to find a HeaderUIElement, so we must not be on a header.
                if (headerElement == null)
                    return;

                // A HeaderUIElement could be the element for the grid caption, a group, or a column.
                // Check if this head has a Group.
                GroupHeader groupHeader = headerElement.Header as GroupHeader;
                if (groupHeader == null)
                    return;

                UltraGridGroup group = groupHeader.Group;
                Debug.WriteLine(group.Key + " clicked");
            }