DataGrid : Add/Edit/Delete Item by Row

Nov 14, 2008 at 2:56 AM

I really appreciate the new DATAGRID control in WPF which I was wondering for days.

Can anyone answer me with VB code for the below queries:
I have 4 textboxes and a datagrid with 4 columns.
1. How to add text from textboxes to datagrid??
2. How to show text in textboxes from selected row in datagrid??
3. How to replace the selected row's text in datagrid with text from textboxes??
4. How to delete the selected row in datagrid??

I appreciate if you can attach as sample.

Thanks in advance.
Nov 14, 2008 at 8:44 AM

I recently published an article on codeproject that demonstrates most of the points you mention. You can view it here:

Note that although the code snippets in the article do not demonstrate sychronisation of the grid with a group of text boxes, the cod download does. A few tips to get you looking in the right
direction ....

I am assuming that you are binding to a collection of business objects.

1. If your collection of objects is an ObservableCollection, all you have to do is add the new object to thw collection and your DataGrid will update accordingly.
2. If you have both your textboxes and DataGrid bound to the same collection, enable synchronisation via the IsSynchronizedWithCurrentItem property of the DataGrid
3. If you have both your textboxes and DataGrid bound to the same collection thsi will happen automatically
4. Simply hit the Delete key!

Colin E.

Nov 15, 2008 at 1:41 AM
Edited Nov 15, 2008 at 1:46 AM
Hi ColinEber,

Thanks for your reply.

I tried your DataGridExamples, but it shows me lot of errors. Can you please send me a simple sample with all those queries.

Note : My datagrid is not binded to any database. Text entered by user in textboxes are added to datagrid.

Thanks in advance.