Solved

Delete row in DGV(DataGridView) using checkboxes

Posted on 2009-04-11
2
535 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: 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

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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 …

734 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