1

I created a DataGrid which I linked to a DataBase (Table). My question is how can I delete a selected row (using btn_click) from the DataGrid and also delete the same data from the DataBase (Table).

Thanks in advance!

1 Answer 1

4

You can access the currently selected item of a DataGrid using the SelectedItem property.

Your can then call the Remove method to remove the item from the DataGrid

var selectedItem = myDataGrid.SelectedItem;
if (selectedItem != null)
{
   myDataGrid.Items.Remove(selectedItem);
}

After the first line you need to extract the information (e.g. some Id) from the item in order to delete it in the database. Usually you cast the SelectedItem to the object you used to bind to the grid.

See also this response.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.