DataGridView - Delete Selected Row
DataGridView - Delete Selected Row
DataGridView - Delete Selected Row
DataGridView - Delete Selected Row
DataGridView - Delete Selected Row
DataGridView - Delete Selected Row DataGridView - Delete Selected Row DataGridView - Delete Selected Row DataGridView - Delete Selected Row DataGridView - Delete Selected Row DataGridView - Delete Selected Row DataGridView - Delete Selected Row DataGridView - Delete Selected Row
DataGridView - Delete Selected Row DataGridView - Delete Selected Row
DataGridView - Delete Selected Row
Go Back  Xtreme Visual Basic Talk > > > DataGridView - Delete Selected Row


Reply
 
Thread Tools Display Modes
  #1  
Old 10-03-2008, 10:08 PM
JoShS JoShS is offline
Newcomer
 
Join Date: Sep 2008
Posts: 1
Default Plese help ....


Edit by Moderator: RE: DataGridView - Delete Selected Row


Hi there :: I find this forum specially the solution to my problem I use these two lines to delete a row in DataGridView and in the DataBase but it do not works:

Code:
    DataGridView1.Rows.Remove(DataGridView1.CurrentRow)
    ColegaTableAdapter.Update(ColegasDataSet)
you talk about DataGridViewRowCollection, whats that ??? and I use these lines to add data to the same DataBase:
Code:
    If (ColegasDataSet.HasChanges()) Then
        SqlDataAdapter1.Update(ColegasDataSet)
        warn2.Visible = True
    Else
        DataGridView1.Refresh()
        warn2.Visible = False
    End If
Please help me. Thanks

Quote:
Originally Posted by IUnknown View Post
If I understand you correctly, you want to delete rows selected by a user from your DGV.

1. Use the DataGridViewRowCollection of your DGV rather than the DataRowCollection of the DataTable. The DataGridViewRow has the Selected property that indicates whether a row is selected or otherwise.

2. Once you have determined that a row is to be deleted, you can use the Remove method of the DataGridViewRowCollection to delete the item from the grid, e.g. YerDataGridView.Rows.Remove(row)

3. Note that at this point, although the item is removed from the DGV, it still has not been deleted from the Access DB. You need to call the TableAdapter Update method on your DataSet/DataTable to commit the deletions to the DB, e.g. YerTableAdapter.Update(YerDataSet)

I normally would call Update once to commit the changes only after having removed all the items to be deleted from the DGV.


Edit by Moderator: Per the posting guidelines please do not reply to threads over one month old and please start your own thread to ask a question. Thank you.

Edit by Moderator: Please use the code tags when posting code. Click on this post's quote button to see how. Thank you.

Last edited by Colin Legg; 10-06-2008 at 08:32 AM.
Reply With Quote
  #2  
Old 10-08-2008, 08:41 PM
chrisace chrisace is offline
Regular
 
Join Date: Oct 2008
Posts: 56
Default

When you call you update statement, you need to specify th table as well. The table adapter should match to the table you are updating.

Example: SomeTableAdapter.Update(Dataset.SomeTable)

Also, you need to have a unique value column in your table in the dataset so that it knows how to perform updates.

Look at this link for info on the DataGridView. http://www.devolutions.net/articles/...#_Toc119903418
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
DataGridView - Delete Selected Row
DataGridView - Delete Selected Row
DataGridView - Delete Selected Row DataGridView - Delete Selected Row
DataGridView - Delete Selected Row
DataGridView - Delete Selected Row
DataGridView - Delete Selected Row DataGridView - Delete Selected Row DataGridView - Delete Selected Row DataGridView - Delete Selected Row DataGridView - Delete Selected Row DataGridView - Delete Selected Row DataGridView - Delete Selected Row
DataGridView - Delete Selected Row
DataGridView - Delete Selected Row
 
DataGridView - Delete Selected Row
DataGridView - Delete Selected Row
 
-->