I have created a form which contains DataGridView and have created first column as checkbox column and fullrowselect is True.
I want like when I click the checkbox of the row or change the checkbox value of the selected row, that particular record should be updated in the database...
I wrote the query properly but facing some problems mentioned below.
Now I first tried in cell click event...
Private Sub DGVHelp_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DGVHelp.CellClick
Try
If PubHelpCode = "ACTMAST" And e.ColumnIndex = 0 Then 'if only checkbox column is clicked
cmd = New SqlCommand("Update FAMPAR SET Tag = '" & DGVHelp(0, e.RowIndex).Value & "' where Account_Code = '" & DGVHelp(1, e.RowIndex).Value & "' ", con1)
ExecuteQuery(con1, "EDITCHECKBOX") ' Its my UDF
DGV_Reset()' This clears the datagrid and fetch the data again
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
When I click the checkbox cell (First column), the event first runs and then the value of the cell is changed... i.e during cellclick event, the DGVHelp(0, e.RowIndex).Value doesn't change its value if its ticked or unticked.
I even tried cellvaluechanged event but it hanged the program by some continuous process that I don't know...
Which event should I use to complete my task??
If any other opinion/idea relating to this task is there then please share...
The Code OneDrive link shared below..
Solution Code link
DataGridViewCheckBox
, the changes which you make on the cell doesn't commit immediately to the data source until you finish editing the cell, then changes will be pushed to data source. TheCellClick
orCellContentClick
will be OK, but you need to commit changes to data source, otherwise the value which you read is not the value which you see. Take a look at this post:DataGridView CheckBox column doesn't apply changes to the underlying bound object – Reza AghaeiCellClick
orCellContentClick
this way. – Reza Aghaei