Back to Devexpress

GridViewBase.DeleteRow(Int32) Method

wpf-devexpress-dot-xpf-dot-grid-dot-gridviewbase-dot-deleterow-x28-system-dot-int32-x29.md

latest5.1 KB
Original Source

GridViewBase.DeleteRow(Int32) Method

Deletes the specified data row.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public virtual void DeleteRow(
    int rowHandle
)
vb
Public Overridable Sub DeleteRow(
    rowHandle As Integer
)

Parameters

NameTypeDescription
rowHandleInt32

An integer value that specifies the handle of the row to delete.

|

Remarks

Use the DeleteRow method to remove a data row. The data row is identified by its handle - a non negative integer value. Refer to Obtaining Row Handles for information on how to obtain row handles.

xaml
<dxg:TableView x:Name="view" AutoWidth="True">
    <dxg:TableView.RowCellMenuCustomizations>
        <dxb:BarButtonItem Name="deleteRowItem" Content="Delete"
            ItemClick="deleteRowItem_ItemClick" />
    </dxg:TableView.RowCellMenuCustomizations>
</dxg:TableView>
csharp
private void deleteRowItem_ItemClick(object sender, ItemClickEventArgs e) {
    GridCellMenuInfo menuInfo = view.GridMenu.MenuInfo as GridCellMenuInfo;
    if (menuInfo != null && menuInfo.Row != null)
        view.DeleteRow(menuInfo.Row.RowHandle.Value);
}
vb
Private Sub deleteRowItem_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs)
    Dim menuInfo As GridCellMenuInfo = TryCast(view.GridMenu.MenuInfo, GridCellMenuInfo)
    If menuInfo IsNot Nothing AndAlso menuInfo.Row IsNot Nothing Then
        view.DeleteRow(menuInfo.Row.RowHandle.Value)
    End If
End Sub

The code sample below shows how to remove rows using a grid command:

xaml
<dxg:TableView x:Name="view" AutoWidth="True">
    <dxg:TableView.RowCellMenuCustomizations>
        <dxb:BarButtonItem Name="deleteRowItem" Content="Delete" 
            Command="{x:Static dxg:GridCommands.DeleteFocusedRow}" />
    </dxg:TableView.RowCellMenuCustomizations>
</dxg:TableView>

The following code snippets (auto-collected from DevExpress Examples) contain references to the DeleteRow(Int32) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

how-to-access-and-remove-rows-by-using-a-custom-cells-context-menu-e1558/CS/Window1.xaml.cs#L19

csharp
if (view.GridMenu.MenuInfo is GridCellMenuInfo menuInfo && menuInfo.Row != null)
        view.DeleteRow(menuInfo.Row.RowHandle.Value);
}

wpf-data-grid-add-and-remove-rows-in-code/CS/AddRemoveRows/AddRemoveRowBehavior.cs#L56

csharp
void DeleteRow() {
    AssociatedObject.DeleteRow(AssociatedObject.FocusedRowHandle);
}

how-to-access-and-remove-rows-by-using-a-custom-cells-context-menu-e1558/VB/Window1.xaml.vb#L24

vb
Dim menuInfo As GridCellMenuInfo = Nothing
    If CSharpImpl.__Assign(menuInfo, TryCast(Me.view.GridMenu.MenuInfo, GridCellMenuInfo)) IsNot Nothing AndAlso menuInfo.Row IsNot Nothing Then Me.view.DeleteRow(menuInfo.Row.RowHandle.Value)
End Sub

wpf-data-grid-add-and-remove-rows-in-code/VB/AddRemoveRows/AddRemoveRowBehavior.vb#L72

vb
Private Sub DeleteRow()
    AssociatedObject.DeleteRow(AssociatedObject.FocusedRowHandle)
End Sub

See Also

Add and Remove Rows

GridViewBase Class

GridViewBase Members

DevExpress.Xpf.Grid Namespace