Solved

Delete row in DGV(DataGridView) using checkboxes

Posted on 2009-04-11
2
534 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:rkckjk
2 Comments
 
LVL 1

Accepted Solution

by:
vwalla earned 500 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:rkckjk
ID: 31569159
thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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