private void Rubout(object sender, RoutedEventArgs e) { Button btn = sender as Button; if (btn != null) { object item = btn.DataContext; if (item != null) { int index = this.SmokingDataBox.Items.IndexOf(item); var a = repo1.FindEntry(index); repo1.Delete(a); } } }