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
160
Selecting rows from multiple band grid based on the mouse selection with shift key
posted

Hi Team,

we are using ultrawingrid for our development. We have a requirement to select rows across the bands when user uses the shift key + mouse down to a row all the rows in either first band or second band should be selected if the first band is expanded.

I tried doing with mouse event but it is not giving me the correct results. Is there a better way to handle this kind of things as the standard functionality is not allowing me to select the rows across bands.

 private Boolean ShiftKey, ControlKey;
        private UltraGridRow InitialRowSelected = null;

        private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
        {
            ShiftKey = false;
            ControlKey = false;
            switch(e.KeyCode)
            {
                case Keys.ShiftKey:
                    ShiftKey = true;
                    break;
                case Keys.ControlKey:
                    ControlKey = true;
                    break;
            }
        }
        
private void ultraGrid1_MouseDown(object sender, MouseEventArgs e)
        {
            Infragistics.Win.UIElement element = ultraGrid1.DisplayLayout.UIElement.LastElementEntered;
            UltraGridRow row = element.GetContext(typeof(UltraGridRow)) as UltraGridRow;

            if (null == row)
            {
                return;
            }

            if (null == InitialRowSelected)
            {
                InitialRowSelected = row;
            }


            if (ShiftKey) // if (row.ParentRow.Selected && ShiftKey)
            {
                //if (row.HasParent())
                //{
                ultraGrid1.Selected.Rows.Clear();
                SelectTheRowsAccrossBand(InitialRowSelected, row);
                //}
            }
}
private void SelectChildBandAllRows(UltraGridRow row)
        {
            UltraGridRow childRow;
            childRow = row.GetChild(ChildRow.First);
            if (null != childRow)
            {
                ultraGrid1.Selected.Rows.Add(childRow);
                while (childRow.HasNextSibling())
                {
                    childRow = childRow.GetSibling(SiblingRow.Next);
                    ultraGrid1.Selected.Rows.Add(childRow);
                }
            }
        }
        private void SelectTheRowsAccrossBand(UltraGridRow InitialRowSelected, UltraGridRow row)
        {
            UltraGridRow ParentRow = InitialRowSelected;
            ultraGrid1.Selected.Rows.Add(InitialRowSelected);

            //Select the parent if any.
            if (row.HasParent())
            {
                ultraGrid1.Selected.Rows.Add(row.ParentRow);
                ParentRow = row.ParentRow;
            }

            //Select itself and before rows.
            ultraGrid1.Selected.Rows.Add(row);
            while (row.HasPrevSibling())
            {
                row = row.GetSibling(SiblingRow.Previous);
                if (row.HasChild() && row.IsExpanded)
                {
                    SelectChildBandAllRows(row);
                }
                ultraGrid1.Selected.Rows.Add(row);
            }



            if (ParentRow != InitialRowSelected)
            {
                while (InitialRowSelected.HasNextSibling())
                {
                    if (InitialRowSelected.IsExpanded)
                    {
                        SelectChildBandAllRows(InitialRowSelected);
                    }
                    InitialRowSelected = InitialRowSelected.GetSibling(SiblingRow.Next);
                    ultraGrid1.Selected.Rows.Add(InitialRowSelected);
                }
            }
            InitialRowSelected = null;
            //while (row.HasNextSibling())
            //{
            //    row = row.GetSibling(SiblingRow.Next);
            //    ultraGrid1.Selected.Rows.Add(row);
            //}


        }

        private void ultraGrid1_MouseUp(object sender, MouseEventArgs e)
        {
            if (ShiftKey)
            {
                InitialRowSelected = null;
                ShiftKey = false;
            }
        }      
  • 29105
    Verified Answer
    Offline posted

    Hello ,

    Selection between multiple hierarchies/bands is considered to be a new product idea. You can suggest new product ideas for future versions (or vote for existing ones) on the following community page.

    Submitting your idea will allow you to communicate directly with our product management team, track the progress of your idea at any time, see how many votes it got, read comments from other developers in the community, and see if someone from the product team has additional questions for you.

    Remember when submitting your idea to explain the context in which a feature would be used and why it is needed as well as anything that would prevent you from accomplishing this today. You can even add screenshots to build a stronger case. Remember that for your suggestion to be successful, you need other members of the community to vote for it.   You can also link back to this thread for additional details.

    Thank you in advance to submitting your product idea.