Solved

Delete row in DGV(DataGridView) using checkboxes

Posted on 2009-04-11
2
531 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
Comment Utility
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
Comment Utility
thanks
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now