This is a migrated thread and some comments may be shown as answers.

Restrict to select one row only at a time

1 Answer 62 Views
PivotGrid and PivotFieldList
This is a migrated thread and some comments may be shown as answers.
nishan
Top achievements
Rank 1
nishan asked on 17 Jun 2016, 04:18 AM

    Dear Telerik.

 

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

Thanks,

 

Nishan.

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 Jun 2016, 09:59 AM
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.
Tags
PivotGrid and PivotFieldList
Asked by
nishan
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or