How to get the value of the cell that was clicked

I am trying to get the value of the cell when click in my viewmodel.  


This is what i have so far. Just do not know what to do next.


//command that get executed when grid row get double clicked

ShowClockedInUserDialog = ReactiveCommand.Create<object>(async (object datagrid) =>

{

    var dg = datagrid as SfDataGrid;

    var cell = dg.CurrentCell; //get row and column of clicked cell


                //How do i get the value of the cell here?

}


xaml grid 

<sfgrid:SfDataGrid

          x:Name="dataGrid"

          AutoGenerateColumnsMode="None"

          SelectionMode="Single"

          SelectedIndex="{Binding SelectedIndex}"

          RowHeight="48"

          HorizontalScrollBarVisibility="Always"

          VerticalScrollBarVisibility="Always"

          GridLinesVisibility="Both"

          HeaderGridLinesVisibility="Both"

          ItemsSource="{Binding EveryoneClockedIn}"

          ColumnWidthMode="Fill">

          <sfgrid:SfDataGrid.Behaviors>

            <toolkit:EventToCommandBehavior

              EventName="CellDoubleTapped"

              Command="{Binding ShowClockedInUserDialog}"

              CommandParameter="{Reference dataGrid}" />

          </sfgrid:SfDataGrid.Behaviors>

</sfgrid:SfDataGrid>


1 Reply

KK Karthikraja Kalaimani Syncfusion Team May 15, 2023 10:09 AM UTC

Hi Mike, 

You can get the cell value by passing current rowdata and column name to the GetValue method() like in the following code snippets. 

Code snippets : 

 <syncfusion:SfDataGrid x:Name="datagrid" ItemsSource="{Binding Orders}"
                               GridLinesVisibility="Both"
                               HeaderGridLinesVisibility="Both"
                               SortingMode="Single"
                               NavigationMode="Cell"
                               SelectionMode="Multiple"
                               HeightRequest="290"
                               WidthRequest="300">
            <syncfusion:SfDataGrid.Behaviors>
                <local:MyBehavior></local:MyBehavior>
            </syncfusion:SfDataGrid.Behaviors>

        </syncfusion:SfDataGrid>

public class MyBehavior : Behavior<SfDataGrid>
{
    protected override void OnAttachedTo(SfDataGrid bindable)
    {
        base.OnAttachedTo(bindable);
        bindable.CellDoubleTapped += CellDoubleTapped;
    }

    private void CellDoubleTapped(object sender, DataGridCellDoubleTappedEventArgs e)
    {
      var CellValue=  (sender as SfDataGrid).View.GetPropertyAccessProvider().GetValue(e.RowData, e.Column.MappingName);
    }

    protected override void OnDetachingFrom(SfDataGrid bindable)
    {
        base.OnDetachingFrom(bindable);
    }
}


We hope this helps, please let us know if you need further assistance from us. 

Regards,
Karthik Raja


Loader.
Up arrow icon