how to get the value of 1 selected cell?

 In the Data Grid, how to get the value of 1 selected cell? That is, when I select 1 cell, I only want to get the value of that selected cell, not all the values of that row.


1 Reply

PS Prathap Senthil Syncfusion Team May 10, 2023 08:54 AM UTC

Hi Qu?c Duong

Thank you for reaching out to us regarding your query on how to get the value of a selected cell in our Data Grid. We understand that you would like to retrieve the value of a single selected cell rather than the values of the entire row. We suggest using the following code snippet to achieve your requirement:


 

<h3> SelectedCellvalue: @cellValue</h3>

 

<SfGrid DataSource="@Orders" @ref="Grid" TValue="Order" AllowSelection="true" AllowPaging="true">

    <GridEvents  CellSelected="CellSelectedHandler" TValue="Order"></GridEvents>

    <GridSelectionSettings  Mode="SelectionMode.Cell" ></GridSelectionSettings>

…..

</SfGrid>

 

@code {

    public List<Order> Orders { get; set; }

    public SfGrid<Order>? Grid { get; set; }

    public object cellValue { get; set; } = null;

 

    public async Task CellSelectedHandler(CellSelectEventArgs<Order> args)

    {

 

        cellValue = args.Data.GetType().GetProperty(Grid.Columns[args.CellIndex].Field).GetValue(args.Data, null);

    }

   

 

}


Documentation: https://blazor.syncfusion.com/documentation/datagrid/events#cellselected

Please let us know if you have further queries.


Regards,
Prathap s


Attachment: BlazorApp2_9761a816.zip

Loader.
Up arrow icon