Restrict to select one row only at a time

2 posts, 0 answers
  1. nishan
    nishan avatar
    8 posts
    Member since:
    May 2015

    Posted 16 Jun Link to this post

        Dear Telerik.

     

    Is there a way to restrict to select one row only at one time?

    Thanks,

     

    Nishan.

  2. Dess
    Admin
    Dess avatar
    1605 posts

    Posted 17 Jun Link to this post

    Hello Nishan,

    Thank you for writing. 

    In order to prevent multiple cell selection in RadPivotGrid with MouseMove, you can use the following code snippet:
    public class CustomPivot : RadPivotGrid
    {
        public override string ThemeClassName 
        {
            get
            {
                return typeof(RadPivotGrid).FullName; 
            }
        }
     
        protected override RadPivotGridElement CreatePivotGridElement()
        {
            return new CustomRadPivotGridElement();
        }
    }
     
    public class CustomRadPivotGridElement : RadPivotGridElement
    {
        protected override Type ThemeEffectiveType    
        {
            get   
            {
                return typeof(RadPivotGridElement);    
            }
        }
     
        public override bool ProcessMouseMove(MouseEventArgs e)
        {
            RadElement element = this.ElementTree.GetElementAtPoint(e.Location);
            PivotCellElement cellElement = element as PivotCellElement;
     
            FieldInfo fi = typeof(RadPivotGridElement).GetField("selecting", BindingFlags.Instance | BindingFlags.NonPublic);
            bool selecting = (bool)fi.GetValue(this);
            if (selecting)
            {
                FieldInfo fi2 = typeof(RadPivotGridElement).GetField("selectionTimer", BindingFlags.Instance | BindingFlags.NonPublic);
                Timer selectionTimer = fi2.GetValue(this) as Timer;
                if (cellElement != null)
                {
                    selectionTimer.Stop();
                    this.SelectCell(cellElement, false, false);
     
                    foreach (PivotRowElement row in this.PivotRowsContainer.Children)
                    {
                        row.Synchronize();
                    }
                }
                else
                {
                    int selectionDirection = 0;
                    Rectangle rect = this.PivotRowsContainer.ControlBoundingRectangle;
     
                    if (e.X < rect.Left)
                    {
                        selectionDirection |= (int)Telerik.WinControls.ArrowDirection.Left;
                    }
                    if (e.X > rect.Right)
                    {
                        selectionDirection |= (int)Telerik.WinControls.ArrowDirection.Right;
                    }
                    if (e.Y < rect.Top)
                    {
                        selectionDirection |= (int)Telerik.WinControls.ArrowDirection.Up;
                    }
                    if (e.Y > rect.Bottom)
                    {
                        selectionDirection |= (int)Telerik.WinControls.ArrowDirection.Down;
                    }
     
                    selectionTimer.Tag = selectionDirection;
     
                    if (!this.PivotRowsContainer.ControlBoundingRectangle.Contains(e.Location))
                    {
                        selectionTimer.Start();
                    }
                    else
                    {
                        selectionTimer.Stop();
                    }
                }
     
                return false;
            }
            return base.ProcessMouseMove(e);
        }
    }

    I hope this information helps. Should you have further questions I would be glad to help.

    Regards,
    Dess
    Telerik
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top