Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

cannot clear datagridview rows, VB.Net

Posted on 2014-01-09
4
Medium Priority
?
1,228 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 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