Edit this page

InputBehavior

RadVirtualGrid manages user mouse and keyboard input over its rows by VirtualGridInputBehavior. By implementing a specific custom input behavior, developers can change the default row functionality or supplement the existing one.

You can find below a sample code snippet demonstrating how to override the default up/down navigation logic when pressing the up/down arrow keys and show a message to confirm the operation. For this purpose, we should create a derivative of VirtualGridInputBehavior and override its HandleUpKey and HandleDownKey methods:

virtualgrid-input-behavior 001

Custom VirtualGridInputBehavior


public class CustomVirtualGridInputBehavior : VirtualGridInputBehavior
{
    public CustomVirtualGridInputBehavior(RadVirtualGridElement gridElement) : base(gridElement)
    {
    }

    protected override bool HandleUpKey(KeyEventArgs keys)
    {
        DialogResult dr = RadMessageBox.Show("Please confirm the move up operation!", "Confirmation", MessageBoxButtons.YesNo);
        if (dr == DialogResult.Yes)
        {
            return base.HandleUpKey(keys);
        }
        return false;
    }

    protected override bool HandleDownKey(KeyEventArgs keys)
    {
        DialogResult dr = RadMessageBox.Show("Please confirm the move down operation!", "Confirmation", MessageBoxButtons.YesNo);
        if (dr == DialogResult.Yes)
        {
            return base.HandleDownKey(keys);
        }
        return false;
    }
}

Public Class CustomVirtualGridInputBehavior
Inherits VirtualGridInputBehavior
    Public Sub New(gridElement As RadVirtualGridElement)
        MyBase.New(gridElement)
    End Sub
    Protected Overrides Function HandleUpKey(keys As KeyEventArgs) As Boolean
        Dim dr As DialogResult = RadMessageBox.Show("Please confirm the move up operation!", "Confirmation", MessageBoxButtons.YesNo)
        If dr = DialogResult.Yes Then
            Return MyBase.HandleUpKey(keys)
        End If
        Return False
    End Function
    Protected Overrides Function HandleDownKey(keys As KeyEventArgs) As Boolean
        Dim dr As DialogResult = RadMessageBox.Show("Please confirm the move down operation!", "Confirmation", MessageBoxButtons.YesNo)
        If dr = DialogResult.Yes Then
            Return MyBase.HandleDownKey(keys)
        End If
        Return False
    End Function
End Class

Apply the custom VirtualGridInputBehavior


this.radVirtualGrid1.VirtualGridElement.InputBehavior = new CustomVirtualGridInputBehavior(this.radVirtualGrid1.VirtualGridElement);

Me.RadVirtualGrid1.VirtualGridElement.InputBehavior = New CustomVirtualGridInputBehavior(Me.RadVirtualGrid1.VirtualGridElement)

note

You can follow a similar approach to customize any of the methods that handle the mouse and keyboard user input.