Solved

Datagridview - updating problems

Posted on 2006-11-01
8
426 Views
Last Modified: 2008-02-01
Have a datagridview hooked up to a dataset on the fly.
The datagridview cells can be individually editted or rows can be selected and editted in bulk fashion.
The bulk edit looks like this:
          For Each row As DataGridViewRow In Me.DataGridView1.SelectedRows
                row.Cells(5).Value = IIf(Me.txtTop.Text = "", 0, Me.txtTop.Text)
                row.Cells(6).Value = IIf(Me.txtBottom.Text = "", 0, Me.txtBottom.Text)
                row.Cells(7).Value = IIf(Me.txtLeft.Text = "", 0, Me.txtLeft.Text)
                row.Cells(8).Value = IIf(Me.txtRight.Text = "", 0, Me.txtRight.Text)
            Next

I then want to traverse each row, see if there was a change that was made and then update the database accordingly.

Have a button that fires this:
Dim tbl As DataTable = ds.Tables(0)
        Try
            For Each row As DataRow In tbl.GetChanges.Rows

                db.CropMasterUpdate(IIf(IsDBNull(row.Item(0)), "", row.Item(0)), _
                                    IIf(IsDBNull(row.Item(1)), "", row.Item(1)), _
                                    IIf(IsDBNull(row.Item(2)), "", row.Item(2)), _
                                    IIf(IsDBNull(row.Item(3)), "", row.Item(3)), _
                                    IIf(IsDBNull(row.Item(4)), "", row.Item(4)), _
                                    IIf(IsDBNull(row.Item(5)), 0, row.Item(5)), _
                                    IIf(IsDBNull(row.Item(6)), 0, row.Item(6)), _
                                    IIf(IsDBNull(row.Item(7)), 0, row.Item(7)), _
                                    IIf(IsDBNull(row.Item(8)), 0, row.Item(8)))
            Next
        Catch ex As Exception

        End Try

For some reason, this doesn't pick up the changes done in the last row selected.  Is it because the last row selected is the current row?  Any way to get around this so that even the current row is updated along with the other rows?
0
Comment
Question by:adwooley2
  • 4
  • 3
8 Comments
 
LVL 39

Assisted Solution

by:appari
appari earned 100 total points
Comment Utility

try calling

detagridview.endedit

method before you call your update procedure
0
 

Author Comment

by:adwooley2
Comment Utility
I was hopeful that was it, but it didn't work.  Any other ideas?
0
 
LVL 39

Expert Comment

by:appari
Comment Utility
did you try

datagridview.update method?
0
 

Author Comment

by:adwooley2
Comment Utility
I'll try this out after I get home (I'm working in Japan, so the night is young).
See you again.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 39

Expert Comment

by:appari
Comment Utility

really:),  me too working in Japan

0
 
LVL 39

Expert Comment

by:appari
Comment Utility

no jangyou?
0
 
LVL 34

Accepted Solution

by:
Sancler earned 200 total points
Comment Utility
DataGridView.EndEdit only commits the editing in the current cell, not the row.  Changes don't get back to the datatable until the ROW is committed.  That requires either a change of row (when the committal of the row that has just been left is automatic) or a forced .EndEdit (or .EndCurrentEdit) of the binding manager.  Which it is - .EndEdit, or .EndCurrentEdit - depends on precisely how the binding is set up.  If there is a BindingSource, then it is .EndEdit on that.  If the binding is direct to the datatable, it needs to be BindingContext(<datatable>).EndCurrentEdit.  Or the other approach would be simply to force a change of row after your bulk edit code.

Roger
0
 

Author Comment

by:adwooley2
Comment Utility
Sancler,
EndCurrentEdit did the magic.  Thank you very much!

ADWooley
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now