Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..
i am using datagrid of wpf toolkit.i am binding datagrid with List data.
i want to delete selected row from datagrid on button click event.
how can i do this?
thanks.
Posted

Hi,

The RemovedItems items reflects the items removed from the selection, and not from the grid.

Handle the PreviewKeyDown event, and use the SelectedItems property to delete the selected rows there:

private void PreviewKeyDownHandler(object sender, KeyEventArgs e) {
var grid = (DataGrid)sender;
if ( Key.Delete == e.Key ) {
foreach (var row in grid.SelectedItems) {
... // perform linq stuff to delete here
}
}
}

try this and let me know
 
Share this answer
 
Hi,

In WPF there is a property "SelectedItem" for selecting a row and "Remove" function for deleting a row.

xamal code:
C#
<datagrid name="datagridTable" selecteditem="{Binding SelectedInformation}">
               ....
</datagrid>


ModalView:
C#
private Information selectedInformation;
public Information SelectedInformation
{
    get { return selectedInformation; }
    set { SetProperty(ref selectedInformation, value); }
}


public UserBase_ViewModal()
{
    delete = new DelegateCommand(DeleteInformationInTable);
}

private void DeleteInformationInTable()
{
   Information.Remove(SelectedInformation);
}






Regards,
R.Karthik
Test Automation
 
Share this answer
 
Have a look at this article:
WPF DataGrid Practical Examples[^]

A lot about WPF Datagrid and it's operations should be clear to you after this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900