We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

SfDataGrid InputBindings

Hello.
I am using SfDataGrid in read-only mode.
This grid have context menu to run different commands from ViewModel at selected item (get info, edit, copy and more).
All is OK.
BUT to "Edit" command i have advanced view (another window).
For user expierence i want to add InputBindings ("Enter" and "Mouse Double click") for run "Edit" command.
Nothing works.
Can you help me?
Example:
...
<syncfusion:SfDataGrid.InputBindings>
    <KeyBinding Gesture="Enter" Command="{Binding DataGridMouseDoubleClickComm,Source={StaticResource MVViewModel}}" />
    <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding DataGridMouseDoubleClickComm,Source={StaticResource  MVViewModel}}" />
 </syncfusion:SfDataGrid.InputBindings>
...
With standart MS DataGrid control this code works perfectly.
P.S. Sorry for my English.

1 Reply

SV Srinivasan Vasu Syncfusion Team April 21, 2016 05:58 PM UTC

Hi Artem,
We have analyzed your query, you can achieve your requirement by creating the custom event triggers instead of InputBindings. You have to create two different custom EventTriggers for MouseDoubleClick and KeyUp event in SfDataGrid. Please refer the below code example and attached sample for more details. 
C#

    //Handle MouseClick


public class EventTriggerExt : System.Windows.Interactivity.EventTrigger

    {

        protected override void OnEvent(EventArgs eventArgs)

        {

            if (this.AssociatedObject is SfDataGrid && eventArgs is MouseButtonEventArgs)

            {

                var args = eventArgs as MouseButtonEventArgs;

                var dataGrid = this.AssociatedObject as SfDataGrid;

                var point = args.GetPosition(dataGrid.GetVisualContainer());

               

                var rowcolindex = dataGrid.GetVisualContainer().PointToCellRowColumnIndex(point, false);


               if (rowcolindex.IsEmpty)

                    return;


                var lineinfo = dataGrid.GetVisualContainer().ScrollColumns.GetVisibleLines().GetVisibleLineAtPoint(point.X);

                if (point.X > lineinfo.ClippedCorner)

                    return;

            }

            base.OnEvent(eventArgs);

        }

    }


    //Handle Enter Key

    public class SpaceKeyDownEventTrigger : System.Windows.Interactivity.EventTrigger

    {


        public SpaceKeyDownEventTrigger() : base("KeyUp")

        {

        }


        protected override void OnEvent(EventArgs eventArgs)

        {

            var e = eventArgs as KeyEventArgs;

            if (e != null && e.Key == Key.Enter)

                base.OnEvent(eventArgs);

        }

    }


XAML

<Syncfusion:SfDataGrid AllowEditing="True" Name="datagrid"                               

                           AutoGenerateColumns="True"

                           ItemsSource="{Binding Orders}"

                           SelectedItem="{Binding Selectedvalue}">     

        <i:Interaction.Triggers>

            <local:EventTriggerExt EventName="MouseDoubleClick">

                <i:InvokeCommandAction Command="{Binding DoubleClickCommand}"/>

            </local:EventTriggerExt>

            <local:SpaceKeyDownEventTrigger EventName="KeyUp">

                <i:InvokeCommandAction Command="{Binding DoubleClickCommand}"/>

            </local:SpaceKeyDownEventTrigger>

        </i:Interaction.Triggers>
    </Syncfusion:SfDataGrid>


Please find the sample from the below location.

Sample Location: http://www.syncfusion.com/downloads/support/forum/123777/ze/SfDataGrid2119996377

Regards,
Srinivasan
 

Loader.
Up arrow icon