I know it could be asked several times over SO but i still need your help. My grid is on some another form where its events are written. In an another form i have the following code which from whcih i am accssing the grid via forms object and exception is coming. I got the following error message :
"Operation did not succeed because the program cannot commit or quit a cell value change."
If objUBFormFieldsTable.TotalPagesInMultiPageClaim - 1 = objUBFormFieldsTable.CurrentSelectedPageNo Then
objfrmVerifyClaimUB04.dgvLineItem.Rows.Clear()
objUBFormFieldsTable.objstruUBLineItems = Nothing
If objfrmVerifyClaimUB04.ValidateLineItemsTotal() = True Then
If MessageBox.Show("Mark IMAGE ID - " & Convert.ToString(intCuurentlySelectedImageId) & " as attachment?", "Mark as attachment[Y/N]?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then
StartWait("Please wait, while submitting current image as ATTACHMENT")
objClaimsInfo.MarkImageAsAttachmentMV(intCuurentlySelectedImageId, gstruCurrentLoggedInUser.intUserID, strImageSubType)
lvwImageList.Items(lvwImageList.SelectedItems(0).Index).ImageIndex = 4
blnLineItemsReadedUB = False
objUBFormFieldsTable = New clsUBFormFieldsTable
loadNextImage()
End If
End If
i have followign events for grid
Private Sub dgvLineItem_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles dgvLineItem.CellBeginEdit
Try
With dgvLineItem.CurrentCell.Style
.BackColor = Color.Yellow
.ForeColor = Color.DarkBlue
.Font = New Font(dgvLineItem.DefaultCellStyle.Font, FontStyle.Bold)
End With
Catch ex As Exception
'MsgBox(ex.Message)
Throw ex
End Try
End Sub
Private Sub dgvLineItem_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvLineItem.CellEndEdit
'Dim strCurrentFieldValue As String
Try
With dgvLineItem.Item(e.ColumnIndex, e.RowIndex).Style
.BackColor = Color.White
.ForeColor = Color.Black
.Font = New Font(dgvLineItem.DefaultCellStyle.Font, FontStyle.Regular)
'.Font = New Font("Arial", 9, FontStyle.Regular)
End With
Catch ex As Exception
'MsgBox(ex.Message)
Throw ex
End Try
End Sub
Private Sub dgvLineItem_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvLineItem.CellEnter
Try
ShowAnnotationForLineItemCell(e.RowIndex, e.ColumnIndex)
dgvLineItem.BeginEdit(False)
'CType(dgvLineItem.CurrentCell, DataGridViewTextBoxEditingControl).TextBox.SelectionLength() = 0
If dgvLineItem.CurrentCell.IsInEditMode AndAlso TypeOf dgvLineItem.EditingControl Is _
DataGridViewTextBoxEditingControl AndAlso Convert.ToString(dgvLineItem.CurrentCell.Value) <> "" Then
SendKeys.Send("{HOME}")
End If
Dim hFocus As Long
Dim hCaret As Long
'Dim pic As Long
hFocus = CLng(GetFocus())
hCaret = CLng(CreateCaret(dgvLineItem.EditingControl.Handle, IntPtr.Zero, 8, dgvLineItem.CurrentRow.Height))
ShowCaret(dgvLineItem.EditingControl.Handle)
Catch ex As Exception
'MsgBox(ex.Message)
Throw ex
End Try
End Sub
Private Sub dgvLineItem_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles dgvLineItem.CellValidating
Try
Dim strSpecialChars() As Char
If blnIsClaimLoaded = True Then
dgvLineItem.EndEdit()
With Convert.ToString(dgvLineItem.CurrentCell.Value)
strSpecialChars = New Char() {"`"c, "~"c, "!"c, "@"c, "#"c, "$"c, "%"c, "^"c, "*"c, "("c, ")"c, "-"c, "_"c, "+"c, "="c, "{"c, "}"c, "["c, "]"c, "|"c, "\"c, ":"c, ";"c, "'"c, "<"c, ">"c, "."c, "?"c}
If .IndexOfAny(strSpecialChars) <> -1 Then
e.Cancel = True
End If
Select Case e.ColumnIndex
Case 0 'REV CODE
If .Length <> 3 Then
e.Cancel = True
End If
Case 1 'CPT
If .Length = 0 Then
Exit Sub
End If
If .Length < 5 Or .Length > 11 Or .Length = 6 Or .Length = 8 Or .Length = 10 Then
e.Cancel = True
End If
Case 2 'NDC
If .Length = 11 Or .Length = 0 Then
Exit Sub
End If
If .Length <> 8 Then
e.Cancel = True
End If
Case 3 'SERV DATE
If .Length = 0 Then
Exit Sub
End If
If .Length <> 8 Or CheckIfValidAndNotFutureDate(.ToString) = False Then
e.Cancel = True
End If
Case 4 'SERV UNIT
If .Length = 0 Then
Exit Sub
End If
If .Length > 5 Then
e.Cancel = True
End If
Case 5 'TOTALCHARGES
If Not IsNumeric(Convert.ToString(dgvLineItem.CurrentCell.Value)) Or Convert.ToString(dgvLineItem.CurrentCell.Value).Contains(".") Then
e.Cancel = True
Else
Exit Sub
End If
End Select
End With
End If
Catch ex As Exception
MsgBox("Error in dgvLineItem_CellValidating " & ex.Message)
End Try
End Sub
i am unable to find out the actual bug, help me....