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
35
Parent/Child grid - I want the multi select to work only within the same parent
posted

I have a parent/child relation in ultrawingrid. I want to be able to select multiple child rows but within the same parent. if the user selects from a different parent, i do not want to allow that selection. Is there any way we can do this?

  • 610
    Offline posted

    For our purposes, using BeforeSelectChange wasn't quite what we wanted as you could still have an active row "selected" under a different parent. We ended up using something like this:

    private void ultraGrid1_BeforeRowActivate(object sender, RowEventArgs e)
    {
        var firstSelectedInBand = ultraGrid1.Selected.Rows.OfType()
            .FirstOrDefault(x => x.Band == e.Row.Band);

        if (firstSelectedInBand == null)
            return;

        if (e.Row.ParentCollection != firstSelectedInBand.ParentCollection)
            ugPlan.Selected.Rows.Clear();
    }

  • 469350
    Suggested Answer
    Offline posted

    Hi,

    There's no property setting of this, but you can do it pretty easily in code.What you do is handle the BeforeSelectChange and loop through the new selected rows. If the collection contains rows from different rows collections, then you cancel the selection.

    Something like this:

            
            void ultraGrid1_BeforeSelectChange(object sender, BeforeSelectChangeEventArgs e)
            {
                if (e.NewSelections.Rows.Count > 1)
                {
                    RowsCollection rows = e.NewSelections.Rows[0].ParentCollection;
                    for (int i = 1; i < e.NewSelections.Rows.Count; i++)
                    {
                        if (e.NewSelections.Rows[i].ParentCollection != rows)
                        {
                            e.Cancel = true;
                            return;
                        }
                    }
                }
            }