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???
Printable View
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???
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
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?
first you have to write the needed steps to edit the text on double clik
now have a submit button which update the value to the database with the value in txtbox .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
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:
But it just doesnt delete the row and sometimes comes with an error: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
system.indexoutofrangeexeption
Start a new thread. This one was RESOLVED.