Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delete row in DGV(DataGridView) using checkboxes

Posted on 2009-04-11
2
Medium Priority
?
541 Views
Last Modified: 2012-05-06
Basically, in my first column I have checkboxes that are unbound.

I would either like to be able to remove the row by checking the checkboxes or clicking a button after a checkbox(s) are checked.

I have some code below that I 've been working with which I found on the web, but it's not working..

thanks

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For Each row As DataGridViewRow In DataGridView1.Rows
            If (row.Cells.Item(0).Value = CheckState.Checked) Then
                DataGridView1.Rows.RemoveAt(0)                                                      'This way doesn't work
                DataGridView1.Rows.Remove(DataGridView1.SelectedRows(0))         'This way doesn't work either  
            End If
        Next
 End Sub

Open in new window

0
Comment
Question by:Richard Kreidl
2 Comments
 
LVL 1

Accepted Solution

by:
vwalla earned 2000 total points
ID: 24121857
I used an unbound checkbox name "chk" for this.

For Each row As DataGridViewRow In DataGridView1.Rows 
If row.Cells("chk").Value = True Then 
DataGridView1.Rows.Remove(row) 
End If 
Next 
Me.FileListBindingSource.EndEdit() 
Me.FileListTableAdapter.Update(Me.FileWatcherDatabaseDataSet.FileList) 

Open in new window

0
 
LVL 2

Author Closing Comment

by:Richard Kreidl
ID: 31569159
thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question