wpf-devexpress-dot-xpf-dot-grid-dot-gridviewbase-dot-deleterow-x28-system-dot-int32-x29.md
Deletes the specified data row.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public virtual void DeleteRow(
int rowHandle
)
Public Overridable Sub DeleteRow(
rowHandle As Integer
)
| Name | Type | Description |
|---|---|---|
| rowHandle | Int32 |
An integer value that specifies the handle of the row to delete.
|
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.
<dxg:TableView x:Name="view" AutoWidth="True">
<dxg:TableView.RowCellMenuCustomizations>
<dxb:BarButtonItem Name="deleteRowItem" Content="Delete"
ItemClick="deleteRowItem_ItemClick" />
</dxg:TableView.RowCellMenuCustomizations>
</dxg:TableView>
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);
}
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:
<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
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
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
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
Private Sub DeleteRow()
AssociatedObject.DeleteRow(AssociatedObject.FocusedRowHandle)
End Sub
See Also