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
195
Selecting rows in group by display based upon context menu set in columnheader
posted

I have a wingrid and I have the OutlookGroupBy display allowed.  Let's say when the program starts, I have no grouping active.  When I right click on a row and it is a header row, I add a context menu to allow the user to select all or none of the rows below the columnheader, as follows:

private void ugUsers_MouseUp(object sender, MouseEventArgs e)

{

UltraGrid grid = (UltraGrid)sender;

if (e.Button != MouseButtons.Right)

{ return; }

_uiElement = grid.DisplayLayout.UIElement.LastElementEntered;

_columnHeader = _uiElement.GetContext(typeof(Infragistics.Win.UltraWinGrid.ColumnHeader)) as Infragistics.Win.UltraWinGrid.ColumnHeader;

if (_columnHeader != null)

{

if (!_columnHeader.Column.Key.StringsAreEqual("Selected"))

{

return;

}

var cmContextMenu = new ContextMenu();

cmContextMenu.MenuItems.Add("Select All", SelectAll_Click);

cmContextMenu.MenuItems.Add("Unselect All", UnselectAll_Click);

cmContextMenu.Show(ugUsers, e.Location);

}

}

The select all and unselect all functions basically just step through all of the rows in the ultragrid collection and either set the selected Boolean value to true or false depending on what context menu item was selected.  This all works fine when I have no groups active (i.e. I've not dragged any column headers into the group by area above the grid.)

What I am trying to figure out though is when I do have my data grouped, say by country name, and I then expand a particular country set of rows, I'd like to only act on those rows within a particular country in a group.  I know that when a grid is grouped, the first row ug.rows[0] is an UltraGridGroupByRow so when I cast the first row to an UltraGridGroupByRow, I can get the children of the groupbyrow, but doing it this way only ever lets me act on the first group's rows because I'm using ug.rows[0] which is the groupbyrow of the first group.  I need to get the groupbyrow of the group that I've just right-clicked the column header of and this is my problem.  How do I get the groupbyrow of the group I just clicked the column header of???

I'm sure there's got to be a way once I have the column header that I just right-clicked on, but I don't see it and looking on the net is not too helpful for such a specific feature.

Thanks for any help you can provide.

  • 21795
    Offline posted

    Hello Donald,

    I have discussed your issue with our more senior developers. There is much more clean solution to this. The column header UIElement also has a context of the rows collection to which it belongs. So to get the rows you need to cast the context to RowsCollection like this:

    private void UgUsers_MouseUp(object sender, MouseEventArgs e)
    {
        UltraGrid grid = (UltraGrid)sender;
        if(grid == null)
            return;

        if(e.Button != MouseButtons.Right)
        { return; }

        _uiElement = grid.DisplayLayout.UIElement.LastElementEntered;
        _columnHeader = _uiElement.GetContext(typeof(Infragistics.Win.UltraWinGrid.ColumnHeader)) as Infragistics.Win.UltraWinGrid.ColumnHeader;

        if(_columnHeader != null)
        {
            if(_columnHeader.Column.Key != "Selected")
            { return; }

            _rows = _uiElement.GetContext(typeof(RowsCollection)) as RowsCollection;
        }

        var cmContextMenu = new ContextMenu();
        cmContextMenu.MenuItems.Add("Select All", SelectAll_Click);
        cmContextMenu.MenuItems.Add("Unselect All", UnselectAll_Click);
        cmContextMenu.Show(ugUsers, e.Location);
    }

    Attached is a simplified version of the project I have sent you implementing this approach.

    Please check my sample and let me know if you have any additional questions on this matter.

    UltraGridSelectGroupedRows_02.zip
  • 21795
    Offline posted

    Hello Donald,

    Yes, you are correct. What you need is a reference to the GroupByRow related to the column header where user right clicked. As of my understanding there is no direct relation between column header and GroupByRow. What you can do, if the group by row connectors are visible, is get the GroupByRowConnectorUIElement located next to the column header where user right clicked. Then you will be able to get the GroupByRow via GetContext method of the UIElement, in this case GroupByRowConnectorUIElement.

    Attached is a small sample project implementing this approach. Please check my sample and let me know if you need any additional information.

    UltraGridSelectGroupedRows.zip