title: how to delete database row as DataGrid row is deleted in wpf?
body: <p>I have a DataGrid in my wpf project which is bound to a datasource and is successfully getting populated with values. Now problem is, how do i respond when user is deleting a row. I also want to delete the same row in database also. My approach is to get the id from <code>lbId</code> column of currently selected row and issue a DELETE query when user presses Delete button on keyboard or the <code>Delete Button</code> in my GUI . How am i supposed to do this?. </p>
  
  <p>Or alternatively Isn't there any thing like <code>UserDeletingRow</code> as in Winforms <code>DataGridView</code>?</p>
  
  <p>Here is the XAML</p>
  
  <pre><code> &lt;DataGrid AutoGenerateColumns="False" Height="430" HorizontalAlignment="Left" Margin="378,61,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="550" ItemsSource="{Binding Path=LocalBookmarks}" CanUserReorderColumns="False" CanUserSortColumns="False" Grid.Row="5" RowEditEnding="datagrid1_RowEditEnding" DataGridRow.Selected="datagrid1_RowSelected"&gt;
          &lt;DataGrid.Columns&gt;
              &lt;DataGridTextColumn Header="Id" Width="20" Binding="{Binding Path=lbId}" CanUserResize="False"&gt;&lt;/DataGridTextColumn&gt;
              &lt;DataGridTextColumn Header="Title" Width="225" Binding="{Binding Path=TitleOfPage}" MaxWidth="250" CanUserResize="True"&gt;&lt;/DataGridTextColumn&gt;
              &lt;DataGridHyperlinkColumn CanUserResize="True" Header="Link" MaxWidth="300" MinWidth="250" Binding="{Binding Path=SiteAddress}"/&gt;
              &lt;DataGridTextColumn Header="Saved On" Width="70" Binding="{Binding Path=DateAdded}" CanUserResize="True"&gt;&lt;/DataGridTextColumn&gt;
          &lt;/DataGrid.Columns&gt;
      &lt;/DataGrid&gt;
  </code></pre>
  
  <p>Here is the image of DataGrid.
  <img src="https://i.stack.imgur.com/XYbi4.png" alt="And just in case the image helps, here it is"></p>
  
  <p>Here is the binding code:</p>
  
  <pre><code>private void BindToData(SqlCeConnectionManger s, int gt, int lt)
      {
          SqlCeDataAdapter sda = new SqlCeDataAdapter("SELECT * FROM LocalBookmarks WHERE lbId &gt; " + gt.ToString() + " AND lbId &lt; " + lt.ToString() + " ORDER BY DateAdded DESC", s.SqlCeCon);
          DataSet dataset = new DataSet();
          sda.Fill(dataset, "LocalBookmarks");
          dataGrid1.DataContext = dataset;
          s.SqlCeCon.Close();     
  
      }
  </code></pre>
  
  <p>Any help will be appreciated.</p>