[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Delete row in Datagrid using checkboxes

Posted on 2009-04-11
16
Medium Priority
?
408 Views
Last Modified: 2012-06-27
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 or boxes are checked.

thanks
0
Comment
Question by:Richard Kreidl
  • 7
  • 6
  • 3
16 Comments
 
LVL 5

Expert Comment

by:brandonvmoore
ID: 24121133
And what exactly is your question in regards to how to implement this functionality?
0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 24121151
I would like the user to be able to check a checkbox so the row would be removed or have a command button when clicked would remove the rows in which the checkboxes are checked.

Not sure if this is what you're asking???
0
 
LVL 5

Expert Comment

by:brandonvmoore
ID: 24121171
Well are you running into an error or is something not acting the way you expect?  If you have a specific technical issue I'll gladly help but I can hardly teach you to program from a comment box.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 2

Author Comment

by:Richard Kreidl
ID: 24121184
Ok, I have some code here that's not working. Now, either I'm way off on how to accomplish this or it just needs some minor changes.

The code below uses the button method which would work, but I'm interested how to do it using the checking of the checkboxes..
 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("select").Value = CheckState.Checked) Then
         DataGridView1.Rows.RemoveAt(row.Index)
         End If
         Next
 
   End Sub

Open in new window

0
 
LVL 5

Expert Comment

by:brandonvmoore
ID: 24121190
OK, I'm a little confused.  You said that you had some code that is not working, but then you said that the code "would work".  Does the code you provided work , but you just want to do it a different way.  Or do you need help getting the code you provided to work?

In the former case, why don't you put your code in an event for the checkbox?  This seems pretty logical to me and I assume you already thought of that so you'll have to let me know why that's not working for you if you've already tried.

In the latter case, let me know what kind of error your getting.
0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 24121255
No, I meant the code I have using the command button doesn't work.

I get the following error:
Column named select cannot be found.
Parameter name: columnName

Not sure how to use the checkbox event when in a datagrid.
0
 
LVL 5

Expert Comment

by:brandonvmoore
ID: 24121348
Run the following:
msgbox(DataGridView1.Rows(1).Cells(1).name)
msgbox(DataGridView1.Rows(1).Cells(2).name)

The results of that might give you a clue.
0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 24121358
I get the error:
Error      1      'name' is not a member of 'System.Windows.Forms.DataGridViewCell'.      
0
 
LVL 5

Expert Comment

by:brandonvmoore
ID: 24121382
Sorry, it's late and I'm not thinking super clearly.

OK, I'm not a DGV expert, but to me that makes is sound like you can't specify the column name to the Cells() collection.  In other words, where you are specifying the word "select", try specifying the number of the column instead.
0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 24121417
Doesn't work...
0
 
LVL 5

Expert Comment

by:brandonvmoore
ID: 24121648
Awesome :)  Well, I was trying to help but I'm no expert on the DGV's and I don't have time to test it out.  So that being the case i would recommend that you repost your question so that it will go back to the top of the list and maybe someone more  knowledgeable on DGV's will see it this time around.

Good luck.
0
 
LVL 1

Accepted Solution

by:
vwalla earned 2000 total points
ID: 24121868

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: 31569148
thanks
0
 
LVL 1

Expert Comment

by:vwalla
ID: 24121906
Glad I could help.
0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 24121921
I get this warning:
Warning      1      property 'Delete' conflicts with sub 'Delete' in the base class 'DataRow' and should be declared 'Shadows'.      

It's coming from this routine:

 <System.Diagnostics.DebuggerNonUserCodeAttribute()> _
        Public Property Delete() As String
            Get
                Try
                    Return CType(Me(Me.tableFirstShift_Checklist.DeleteColumn), String)
                Catch e As System.InvalidCastException
                    Throw New System.Data.StrongTypingException("The value for column 'Delete' in table 'FirstShift_Checklist' is DBNull.", e)
                End Try
            End Get
            Set(ByVal value As String)
                Me(Me.tableFirstShift_Checklist.DeleteColumn) = value
            End Set
        End Property
0
 
LVL 1

Expert Comment

by:vwalla
ID: 24124339
Looks like there is a conflict i n a namespace somewhere.  What does your delete look like?  Are you doing this manually?
What version of VS are you using and what DB are you using on your backend?
If you can post a zip of your project I can try to pick through it.  Maybe if your column for delete is bound?? May cause an issue...not sure.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Article by: Jorge
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses
Course of the Month9 days, 18 hours left to enroll

591 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