CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2000
    Posts
    200

    Delete a row from DataGrid

    Using a data environment (MS Jet 4.0 DB Provider). Have set up commands for each of the 4 tables (not using SQL statements). In frmMain, have DataGrid control with source of deTransfers & member of Location (1 of the tables = command).

    The control includes all rows (fields) of the Location table, as it should. Have written procedures to add, edit, & delete a row. Using code below, when user deletes a row, gets error . . . "Row handle referred to a deleted row or a row marked for deletion." HOWEVER, when I step through (F8), execution does not stop! Works fine. Row gets deleted from record set & DB! When I do not step through & execution halts & I press Debug, execution is on the line following .Delete.

    What is going on? Thanks for any s****.
    John



    private Sub mnuDeleteLocation_Click()
    on error GoTo HandleError
    With deTransfers.rsLocation
    .Delete 'Delete the current record
    .MoveNext 'EXECUTION stops here (after .Delete) when NOT debugging - Move to the following record
    If .EOF then 'If last record deleted
    .MovePrevious
    If .BOF then 'If BOF and EOF true, no records remain
    MsgBox "The recordset is empty.", vbInformation, "No records"
    End If
    else: .MoveFirst
    End If
    End With

    Exit Sub

    HandleError:
    MsgBox "Unable to carry out requested action.", vbInformation, "Video Bonanza"
    on error GoTo 0


    End Sub





  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Delete a row from DataGrid

    You are running into asynchronous processing problems. Stepping through at the speed of mouse clicks allows ADO or whatever to complete its work before running into problems.
    Try doing a .Refresh or .Requery after the initial deletion

    John G

  3. #3
    Join Date
    Sep 2000
    Posts
    200

    Re: Delete a row from DataGrid

    John, thanks for the suggestion. I tried .Requery but still get message. RecordSet has no .Refresh, but I tried .Resync, but still no change.

    Sure appreciate any other s****. from you.
    John R.


  4. #4
    Join Date
    Sep 2000
    Posts
    200

    Re: Delete a row from DataGrid

    John, thanks for the suggestion. I think I've tried everything. It seems like this problem would be more known. (?)

    Anyway, would sure appreciate it if you have time to look at it one more time. It's the 1st problem I've had you have not solved (little incentive)! Hey, we're talkin' 10 points . . I'd give you a 1000 if I knew how.

    Thanks in any event,
    John


  5. #5
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Delete a row from DataGrid

    John,
    I went through the Application Wizard and created a program that uses the Biblio.mdb file using ADO code (Jet 4.0) and the delete code it generated is almost identical to yours so I suspect some external environment is killing you.
    Where is your DataBAse located (Server/Local) etc.
    Try putting in a DOEVENTS in the delete routine to allow other processes to gain control.
    Also I suggest you create a new project and use the data Form Wizard using your database and environment to see what kind of code it generates. Although it does not generate perfect code, it does work under optimal conditions

    John G

  6. #6
    Join Date
    Sep 2000
    Posts
    200

    Re: Delete a row from DataGrid

    John, thanks for your suggestion about using the Data Form Wizard. I started from scratch, and the app. will delete without error, using my database! So, I'll just try to find the code differences . . . or just go with theirs.

    When using the Data Form Wizard, I noticed that using a Class was an option, instead of direct ADO coding. Seems so neat, using a class. Would you suggest that, or stay with ADO coding on the form itself?

    Thanks again,
    John


  7. #7
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Delete a row from DataGrid

    Go with what works or you understand for the time. Once you get it working then play with class modules. If you never used them before, they can be a little confusing. But once you get the gist of a class module, they are most rewarding and flexible.

    John G

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured