code to loop thru the checkboxes and read their status and do some operation

By Sakshi a

This vb.net code loops through the checkboxes in a datagridview control and reads their status and do one updation to a global object. This will be mostly used in grid based pages where we need to check status of some field and do some relative task based on that. Even you can reuse this login in all grid controls. Also it is properly encasulated into exception handling mechanism.

Private Sub btnUpdate_Click(ByVal  sender As System.Object, ByVal e As System.EventArgs ) Handles btnUpdate.Click

Try

Dim j As Integer

If MsgBox("Are you Sure ?", MsgBoxStyle.YesNo + MsgBoxStyle.Critical, "Confirmation") = MsgBoxResult.Yes Then

For j = 0 To Me.dgdvConStatus.Rows.Count - 1

Dim ck As DataGridViewCheckBoxCell

Dim nrow1 As Integer = j

ck =
Me.dgdvConStatus.Rows(j).Cells("chkstatus")

If ck.Value = True Then

g_objDbAccess.UpdateContentLocally(
Me.dgdvConStatus.Rows(j).Cells(1).Value(), "1")

ElseIf ck.Value = False Then

g_objDbAccess.UpdateContentLocally(
Me.dgdvConStatus.Rows(j).Cells(1).Value(), "0")

End If

Next

MsgBox(
"Content Status Updation done Successfully")

End If

Catch ex As Exception

MsgBox(
" Error : " & ex.Message)

End Try

End Sub

code to loop thru the checkboxes and read their status and do some operation  (724 Views)