Skip to main content

DxDataGrid<T>.RowRemoving Event

Occurs when a user removes a data row.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v22.1.dll

Declaration

[Parameter]
public Action<T> RowRemoving { get; set; }

Parameters

Type Description
T

A data item type that is passed to a delegate method as a parameter.

Remarks

Important

The Data Grid was moved to maintenance support mode. No new features/capabilities will be added to this component. We recommend that you migrate to the Grid component.

Handle the RowRemoving event to remove the data item from the Data Grid’s data source or discard changes.

To control the visibility of the Delete command button, use the DeleteButtonVisible property.

@using System.Collections.ObjectModel

<DxDataGrid Data="@weatherForecasts"
            RowRemoving="@((dataItem) => OnRowRemoving(dataItem))">
    <DxDataGridCommandColumn />
    <DxDataGridDateEditColumn Field="@nameof(WeatherForecast.Date)" />
    <DxDataGridSpinEditColumn Field="@nameof(WeatherForecast.TemperatureC)" />
    <DxDataGridColumn Field="@nameof(WeatherForecast.CloudCover)" />
    <DxDataGridCheckBoxColumn Field="@nameof(WeatherForecast.Precipitation)" />
</DxDataGrid>

@code {
    public class WeatherForecast {
        public DateTime Date { get; set; }
        public int TemperatureC { get; set; }            
        public string CloudCover { get; set; }
        public bool Precipitation { get; set; }
    }

    static readonly Random random = new Random();
    readonly ObservableCollection<WeatherForecast> weatherForecasts = new ObservableCollection<WeatherForecast>();

    protected override void OnInitialized() {
        String[] CloudCover = {"Sunny", "Partly cloudy", "Cloudy", "Storm"};

        foreach (var date in Enumerable.Range(1, 30).Select(i => DateTime.Now.Date.AddDays(i))) {
            weatherForecasts.Add(new WeatherForecast() {
                Date = date,
                TemperatureC = random.Next(10, 20),
                Precipitation = Convert.ToBoolean(random.Next(0, 2)),
                CloudCover = CloudCover[random.Next(0,CloudCover.Length)]
            });
        }
    }

    void OnRowRemoving(WeatherForecast item) {
        weatherForecasts.Remove(item);
    }
}

Note

If you bind the data grid to a data source that does not implement the INotifyCollectionChanged interface, you should reload data and redraw the grid after a row is deleted. To do this, use the Refresh method in the OnRowRemoving handler.

Run Demo: Data Grid - Column Types

See Also