?
Solved

cannot clear datagridview rows, VB.Net

Posted on 2014-01-09
4
Medium Priority
?
1,166 Views
Last Modified: 2016-02-10
I have a VB.net datagridview in a project, unbound.  In the RowValidated event, I determine whether I need to make a database write.  If I do make a database write, I want to refill the grid, as I need the identity column of the newly added row to appear in the grid.

I use linq to sql to make the database writes, so, while still in the RowValidated event, I call dc.SubmitChanges, then I call my FillGrid (see code).  As soon as I execute the line Me.dgvMKL.Rows.Clear(), I get the error:

Operation cannot be performed in this event handler.

Is there something I need to do to commit the grid or some such thing before trying to clear the rows?  I tried invoking the EndEdit method in the RowValidated event, but that didn't help.

Thanks,

 Private Sub FillGrid()
        Try

            Me.dgvMKL.Rows.Clear()

            Dim dc As dcKittingdc = New dcKittingdc(Me._ConnString)

            Dim MKLRecs As IQueryable(Of MKL) = From i In dc.MKLs
                                                Where i.Job_Number = Me.tJob.Text _
                                                AndAlso i.SS_Number = Me.tSS.Text _
                                                AndAlso i.Install = Me.cbInstall.Text
                                                Select i

            For Each MKLRec As MKL In MKLRecs
                Me.dgvMKL.Rows.Add(MKLRec.Job_Number, _
                                   MKLRec.SS_Number, _
                                   MKLRec.Install, _
                                   MKLRec.Real_Part_Number, _
                                   MKLRec.Qty.ToString(), _
                                   MKLRec.uom, _
                                   MKLRec.Active, _
                                   MKLRec.User, _
                                   MKLRec.DateTime.ToString(), _
                                   MKLRec.Top_Collector, _
                                   MKLRec.MKL_Id.ToString())
            Next
        Catch ex As Exception
            Throw New Exception("At FillGrid/frmEditMKL: " + ex.Message)
        End Try
    End Sub

Open in new window

0
Comment
Question by:g_johnson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 39768212
have you tried dgvMKL.DataSource = Nothing
0
 
LVL 4

Author Comment

by:g_johnson
ID: 39768502
The grid is never bound, but I tried this anyhow.  No luck.
0
 
LVL 4

Accepted Solution

by:
g_johnson earned 0 total points
ID: 39769229
I solved this using information I found here:

http://stackoverflow.com/questions/4960232/operation-cannot-be-performed-in-this-event-handler


I used a timer.
0
 
LVL 4

Author Closing Comment

by:g_johnson
ID: 39778779
Solves the problem, no other viable solutions offered
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question