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
320
Accessing value of a GroupBy Header
posted

Hi,

I have a WinGrid where I have a Groupby Header (see picture below).

Is it possible when clicking on one row to retrieve the value of the grouped by column (in the sample the "Donnerstag, 28.. Oktober 2010")?

Thanks in advance if anybody has an idea.

Regards,

Oliver

 

  • 3707
    posted

    Here's an alternate method to Danko's idea that would also use the MouseDown event of the grid.

    private void ultraGrid1_MouseDown(object sender, MouseEventArgs e)
    {
        String groupbytext = String.Empty;
        if (ultraGrid1.DisplayLayout.UIElement.ElementFromPoint(e.Location) is DependentTextUIElement &&
            ultraGrid1.Selected.Rows.Count > 0 && ultraGrid1.Selected.Rows[0].IsGroupByRow == true)
            groupbytext = ((UltraGridGroupByRow)ultraGrid1.Selected.Rows[0]).ValueAsDisplayText;
    }

    The code snippet here is dependent on the user clicking the GroupBy row.

     

  • 469350
    Verified Answer
    Offline posted

    Do you really want the value only when the user clicks on the row? What if they activate the row using the keyboard?

    If you only care about clicking, then using MouseDown as Danko suggested is a good way to go. If you just want to track when the ActiveRow changes, I would do it like this:


            private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
            {
                UltraGrid grid = (UltraGrid)sender;
                if (grid.ActiveRow != null && grid.ActiveRow.IsGroupByRow)
                {
                    UltraGridGroupByRow groupByRow = (UltraGridGroupByRow)grid.ActiveRow;
                    Debug.WriteLine((groupByRow.Value);
                }
            }

    Either way, you get the value by casting the row into an UltraGridGroupByRow and then using the Value property.

  • 20872
    Suggested Answer
    Offline posted

    Hello Oliver,

    One possible apporach might be using MouseDown event of the UltraGrid and get the value of the GroupByRow like the following:

     

      private void ultraGrid1_MouseDown(object sender, MouseEventArgs e)
            {
                GroupByRowUIElement rowUI = Get(((sender as UltraGrid).DisplayLayout.UIElement.ElementFromPoint(e.Location)));
                if( rowUI != null)
                {

                   //get the desired value of the clicked GroupByRow
                    rowUI.GroupByRow.Value.ToString();
                }
            }

            private GroupByRowUIElement Get(UIElement elemet)
            {
                if (elemet == null)
                    return null;
                if (elemet is GroupByRowUIElement)
                    return (GroupByRowUIElement)elemet;
                return Get(elemet.Parent);

            }

    Please let me know if this is not what you are looking for.