[RESOLVED] Remove DGV ros via Quary
I am using a quary to search and show results in a databound DGV on the fly
Like so
(THIS WORKS FINE)
Code:
Try
Me.FilesTableAdapter.NewProfile(Me.FilesDataSet.Files, NameTextbox.Text)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
i need to know how to delete all the found results
i.e
If someone clicks a Delete Button on the form then it runs this quary and deletes all found results
Re: Remove DGV ros via Quary
In your code, 'Me.FilesDataSet.Files' is the DataTable that contains all the records. One option is to loop through that DataTable and call the Delete method of each row, then call Update on the table adapter.
Re: Remove DGV ros via Quary
Would you be able to do a brief example of that sorry i get what you are saying just dont know how i would do it mainly the loop part
Re: Remove DGV ros via Quary
i just tried
Code:
For Each row As DataRow In FilesDataGridView.Rows
' Try
' Me.FilesTableAdapter.NewProfile(Me.FilesDataSet.Files, Prifle_NameTextBox.Text)
' Catch ex As System.Exception
' System.Windows.Forms.MessageBox.Show(ex.Message)
'End Try
Me.FilesBindingSource.RemoveCurrent()
Next
But i keep getting an error
Invalid cast exception was unhandled
unable to cast object of type 'system.windows.forms.datagridviewrow' to type 'system.datarow'
Re: Remove DGV ros via Quary
this works but it doesnt loop all the way it deletes a few and not all rows on the datgridview
Code:
For Each row As DataGridViewRow In FilesDataGridView.Rows
Me.FilesBindingSource.RemoveCurrent()
Next
Me.FilesBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.FilesDataSet)
Re: Remove DGV ros via Quary
You're looping through the DataGridView and calling RemoveCurrent on the BindingSource. I said:
Quote:
loop through that DataTable and call the Delete method of each row
Re: Remove DGV ros via Quary
Re: Remove DGV ros via Quary
If you can loop through one collection then you can loop through any collection. A typed DataTable, which you're using, is a collection just like the Rows of a DataGridView. You don't have to be taught how to drive every different car. Drive one, drive 'em all. Same goes for looping through collection. As for calling the Delete method, it's calling a method. Call one method, call 'em all. Programming is about taking what you know and applying it to similar but not identical situations. Try it.
Re: Remove DGV ros via Quary
got it with
Code:
For Each AttachedFile As DataRow In FilesDataSet.Tables(0).Rows
If (AttachedFile("File_Profile") = Prifle_NameTextBox.Text) Then
AttachedFile.Delete()
End If
Next
FilesDataSet.Tables(0).AcceptChanges()
Me.ProfilesBindingSource.RemoveCurrent()
well it seems to work any way ;)