Tuesday, May 21, 2024
HomeiOS Developmentsqlite - DataGridView returns "Operation can't be carried out on this occasion...

sqlite – DataGridView returns “Operation can’t be carried out on this occasion handler” on .Rows.Clear() in VB.internet


I have been writing a database software to go together with a private challenge, and given my self-taught coding expertise I am shocked I’ve gotten so far as I’ve. A long time in the past, I coded dBase/Clipper, then did pretty effectively with VB6 at a borderline average degree, and ceased coding altogether until now. I got here again to it out of want, discovering myself working with VB.internet (2022), which I needn’t say may be very totally different from VB6, and SQLite. I’ve picked up VB.internet pretty effectively and have been in a position to resolve most of my coding issues unaided. However now I’ve one situation that has me stumped:

The shape hundreds knowledge from two columns in a single (supply) desk right into a DataGridView (DGV). Choosing a row checks the report and nominally permits for including data pertinent to it into a distinct desk. The supply desk additionally has a column (Boolean) which, if set TRUE raises a immediate to the person. If the response is YES, the report may be processed as if it had been FALSE. This route units a flag on the supply report so it’s excluded from the DGV on the subsequent iteration. Nonetheless, when the response is NO, the report will get the exclusion set, after which the shape resets. To perform the reset, I clear the whole DGV with .Rows.Clear() after which reload it from scratch.

When there isn’t any immediate, or when there’s and the response is YES, the DGV clears and reloads as anticipated. Nonetheless, if there’s a immediate and the response is NO, I get an “Operation can’t be carried out on this occasion handler” error. Code fragments observe:

Code to deal with the reset situation described above:

    Personal Sub DataGrid_SelectRow(sender As Object, e As DataGridViewCellEventArgs) Handles dgvRecords.RowEnter

        ' *** Code to arrange a number of issues for regular processing ***

        If strDGVCell01 <> "" Then
            If FLBG_TableColumnLookup(appDataSource, tableArchive, strFilterString, "[BlankFrame]") = True Then
                If FLBG_CustomMsgBox(strDGVCell01 & " " & noticeBlankFrame, __ModuleLongName, "QYN") = vbNo Then
                    FLBG_TableRecordUpdate(appDataSource, tableArchive, "[InLibrary]=True", strFilterString)
                    RecycleForm()
                    Exit Sub
                Finish If
            Finish If
        Finish If

        LookupArchiveRecordDetails()
        LookupMediaRecordDetails()
        txtYear.Choose()
    Finish Sub

Code to recycle the shape:

   Personal Sub RecycleForm()
       ResetVariables()
       UpdateImageViewport(False, pctImgPreview, strSourceFileFQN, btnViewImage, lblResolutionPX, lblFileSize)
       FLBG_PopulateDataGridFromDB(dgvRecords, appDataSource, tableArchive, strDGVColumns, "[InLibrary]=False", strDGVSortFilter)
       dgvRecords.CurrentCell = Nothing
       grpLibrary.Choose()
   Finish Sub

…and the code that resets the variables (together with the DGV):

    Personal Sub ResetVariables()
        blnImageInLibrary = False
        blnGotArchiveNotes = False
        chkAltSrc.Checked = False
        cmbAltSrc.SelectedIndex = -1
        rdoModReg.Checked = True
        strFileBase = ""
        strFileMods = ""
        strFileSNum = ""
        strFileType = ""
        strFileVary = ""
        strPathYear = ""
        strSourceFileFQN = ""
        lblFQN.Textual content = ""
        lblNumber.Textual content = "______"
        txtNote.Clear()
        txtYear.Clear()
        txtVariant.Clear()
        dgvRecords.Rows.Clear()         ' *** Error occurs right here ***
        intCountNew = Nothing
        intCountOld = Nothing
        strConditionString = ""
        strFilterString = ""
        strLookupValue = ""
    Finish Sub

Lastly, the code that handles a traditional report replace (“Save” button):

    Personal Sub Button_AddUpdate(sender As Object, e As EventArgs) Handles btnAdd.Click on

        ' *** Code to arrange a number of issues for regular processing ***

        strConditionString = strValue05 & "," & strValue06 & "," & strValue04 & "," &
                             strValue03 & "," & rdoModC2M.Checked & "," &
                             rdoModM2C.Checked & "," & strValue07 & "," &
                             strValue08 & "," & strValue09
        FLBG_TableRecordInsert(appDataSource, tableLibrary, strColumnFilter, strConditionString)
        FLBG_TableRecordUpdate(appDataSource, tableYearTally, "[LastCount]=" & intCountNew, "[Year]=" & strValue01)
        FLBG_TableRecordUpdate(appDataSource, tableArchive, "[InLibrary]=" & blnImageInLibrary, strFilterString)

        RecycleForm()
    Finish Sub

Backside line? I am unsure what I am lacking right here. The one distinction is that the one which works is initiated from a Button Object occasion, whereas the opposite is initiated off a dialog Y/N immediate. If that finally ends up being the explanation, then I do not know set off it with out including a button object click on proper after the Y/N…

I did some digging about this error, and the closest I get is that this older SO article, “Operation can’t be carried out on this occasion handler“, and others prefer it on different websites. Nonetheless, in all these cases, the builders asking the query are attempting to take away only one row from the content material of the DGV. In distinction, I am zapping the entire thing. However, I’ve tried all the options posited to no avail, besides these referring to altering the desk binding as that does not apply (the desk is not certain).

If it helps any, listed here are the error particulars:

System.InvalidOperationException
  HResult=0x80131509
  Message=Operation can't be carried out on this occasion handler.
  Supply=System.Home windows.Types
  StackTrace:
   at System.Home windows.Types.DataGridViewRowCollection.Clear()
   at ILiAD.ILiAD_ManageImageLibrary.ResetVariables() in F:DevelopmentApplicationCodeBasicVB 2022ILiADILiAD_ManageImageLibrary.vb:line 667
   at ILiAD.ILiAD_ManageImageLibrary.RecycleForm() in F:DevelopmentApplicationCodeBasicVB 2022ILiADILiAD_ManageImageLibrary.vb:line 635
   at ILiAD.ILiAD_ManageImageLibrary.yadda() in F:DevelopmentApplicationCodeBasicVB 2022ILiADILiAD_ManageImageLibrary.vb:line 368
   at ILiAD.ILiAD_ManageImageLibrary.DataGrid_SelectRow(Object sender, DataGridViewCellEventArgs e) in F:DevelopmentApplicationCodeBasicVB 2022ILiADILiAD_ManageImageLibrary.vb:line 355
   at System.Home windows.Types.DataGridView.OnRowEnter(DataGridViewCellEventArgs e)
   at System.Home windows.Types.DataGridView.OnRowEnter(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean canCreateNewRow, Boolean validationFailureOccurred)
   at System.Home windows.Types.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)
   at System.Home windows.Types.DataGridView.OnCellMouseDown(HitTestInfo hti, Boolean isShiftDown, Boolean isControlDown)
   at System.Home windows.Types.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs e)
   at System.Home windows.Types.DataGridView.OnMouseDown(MouseEventArgs e)
   at System.Home windows.Types.Management.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
   at System.Home windows.Types.Management.WndProc(Message& m)
   at System.Home windows.Types.DataGridView.WndProc(Message& m)
   at System.Home windows.Types.Management.ControlNativeWindow.OnMessage(Message& m)
   at System.Home windows.Types.Management.ControlNativeWindow.WndProc(Message& m)
   at System.Home windows.Types.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Home windows.Types.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Home windows.Types.Software.ComponentManager.System.Home windows.Types.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 motive, Int32 pvLoopData)
   at System.Home windows.Types.Software.ThreadContext.RunMessageLoopInner(Int32 motive, ApplicationContext context)
   at System.Home windows.Types.Software.ThreadContext.RunMessageLoop(Int32 motive, ApplicationContext context)
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
   at ILiAD.My.MyApplication.Predominant(String[] Args) in :line 83



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments