-
October 27th, 2009, 06:28 AM
#1
[RESOLVED] Delete Row From DataGridView
hello frnds, I bound the DataGridView with Database.I have checkboxes in the first column.
I want that on button click,delete rows whose checboxes are checked,Can somebody tell me???
-
October 27th, 2009, 06:34 AM
#2
Re: Delete Row From DataGridView
check this code. The click on the first column will make the check box selected or not selected. Then when you press the delete button, the rows where the checkbox status is true will get deleted.
Code:
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles empview.CellContentClick
Try
Dim x, y As Short
Dim bcall As Boolean
x = DataGridView .CurrentCellAddress.X
y = DataGridView .CurrentCellAddress.Y
If x = 0 Then
bcall = DataGridView .Item(x, y).Value
If bcall = True Then
DataGridView .Item(x, y).Value = False
Else
DataGridView .Item(x, y).Value = True
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
Private Sub btnDlt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDlt.Click
For j = 0 To DataGridView .RowCount - 1
bcall = DataGridView .Item(0, j).Value
If (bcall = True) Then
empid = DataGridView .Item(2, j).Value
cmd = New OleDbCommand(" delete from employee where empid = " & empid & " ", cn)
cmd.ExecuteNonQuery()
End Try
End Sub
-
October 27th, 2009, 07:10 AM
#3
Re: Delete Row From DataGridView
Thx makdu,very Much. Hi makdu, I want to update data in Gridview,Suppose we double click on cell & edit text,I want the data to be updated in Database also,In which event,I write the code for updation.Can You tell me?
Last edited by sonia.sardana; October 27th, 2009 at 07:25 AM.
-
October 28th, 2009, 12:21 AM
#4
Re: [RESOLVED] Delete Row From DataGridView
first you have to write the needed steps to edit the text on double clik
Code:
Private Sub empview_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles empview.CellContentDoubleClick
Dim x, y As Short
x = DataGridView .CurrentCellAddress.X
y = DataGridView .CurrentCellAddress.Y
txtbox1.text= DataGridView .Item(x, y).Value
End Sub
now have a submit button which update the value to the database with the value in txtbox .
-
October 29th, 2010, 06:11 AM
#5
Re: [RESOLVED] Delete Row From DataGridView
Hi,
I am also trying to delete a row by a button click. I added a new column with a checkbox which I am going to use like this:
Code:
For Each row As DataGridViewRow In Database_installDataGridView.Rows
If Not row.IsNewRow Then
If row.Cells(Checkbox.Index).Value = True Then
MsgBox("checked")
Database_installDataGridView.Rows.Remove(row)
Else
MsgBox("0")
End If
End If
Next
But it just doesnt delete the row and sometimes comes with an error:
system.indexoutofrangeexeption
-
October 29th, 2010, 01:35 PM
#6
Re: [RESOLVED] Delete Row From DataGridView
Start a new thread. This one was RESOLVED.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|