Get selected row in FlexGrid

Posted by: andy.richard on 15 June 2023, 6:53 am EST

  • Posted 15 June 2023, 6:53 am EST

    Is there a way to get the selected row in FlexGrid? I can’t seem to see anything like that. I can get the value of a cell but I can’t figure out how to get the full row. For example, if the row is an Employee type, I should be able to get the row as an Employee object.

  • Posted 20 June 2023, 4:55 am EST - Updated 20 June 2023, 5:00 am EST

    Hi Andy,

    To get the row data, you could use the grid.Rows[RowIndex].DataItem to get the row data for a particular row. To get the selected row, you could use the grid.Selection.Row.

    Kindly refer to the following code snippet and the attached sample:

        private async void GetRowData()
        {
            if(grid.Selection != null)
            {
                int selectedRowIndex = grid.Selection.Row;
                WeatherForecast rowVal = (WeatherForecast)grid.Rows[grid.Selection.Row].DataItem;
                string rowValString = "Date: " + rowVal.Date.ToString() + " Temperature C: " + 
                rowVal.TemperatureC.ToString() + " Temperature F: " + rowVal.TemperatureF.ToString() + 
                " Summary: " + rowVal.Summary.ToString();
                await js.InvokeVoidAsync("console.log", rowValString);
            }
        }

    References:

    Selection Property: https://www.grapecity.com/componentone/docs/blazor/online-blazor/C1.Blazor.Grid~C1.Blazor.Grid.FlexGrid~Selection.html

    DataItem Property: https://www.grapecity.com/componentone/docs/blazor/online-blazor/C1.Blazor.Grid~C1.Blazor.Grid.GridRow~DataItem.html

    Regards,

    Ankit

    Sample: FlexGrid_Row_Data.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels