hey everyone,
got a little problem. Let's say I have 2 docuents in my xamdatagrid and I only want to remove 1 of them. So I'll highlight it and click my delete button. the only problem is I dont konw which option will only select the highlighted record. i either delete both or niether. here's the code that I have so far.
Private Sub Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnDelete.Click
If xamDocGrid.ActiveRecord Is Nothing Then
MessageBox.Show("You must select a document to Delete", "No Active Document Warning", MessageBoxButton.OK, MessageBoxImage.Information) Else ' For Each row As DataRow In dtDocs.Rows ' If Not xamDocGrid.ActiveRecord Is Nothing Then xamDocGrid.Records.ElementAt()
' row.Item("Active") = False
'End If
'Next
Try For Each row As DataRow In dtDocs.Rows
If row.Item("Active") = False Then row.Delete() End If
Next Catch ex As Exception Return
End Try
thanks in advance
Joel
Hi,
If you want to learn how you can select a whole record by clicking on an individual cell and then delete the selected record I advise you to become familiar with the solution at http://forums.infragistics.com/forums/t/5652.aspx in reply to the question - "How to delete the currently selected DataRecord ?".
Best Regards,Yanko
hey,
it does work like you were saying, i was just clicking on the individual cell not the whole record. so just gotta find a way to click on a cell and get the whole record to become selected.
thanks again
Jeremy hello,
Thank you for that bit of code I definatley think this will help me out, but i think i must be doing it wrong or not declaring something right because when i try to delete a record from my datagrid i can step through the code no problem but it doesn't delete the record from my datagrid. not sure if there was something I'm missing.
heres the code that im using
MessageBox.Show("You must select a document to Delete", "No Active Document Warning", MessageBoxButton.OK, MessageBoxImage.Information)
Else
DataPresenterCommands.DeleteSelectedDataRecords.Execute(Nothing, xamDocGrid)
xamDocGrid.UpdateLayout()
end if
Thanks in advance,
That was the route I started to take, but it is way to much work. The trick is to use WPF's Routed Commands. In this case, the entire button-click handler can be handled like this:
MessageBox.Show("You must select a document to Delete", "No Active Document Warning", MessageBoxButton.OK, MessageBoxImage.Information) Else
DataPresenterCommands.DeleteSelectedDataRecords.Execute(nothing, xamDocGrid)
End If