Solved

Datagridview - updating problems

Posted on 2006-11-01
8
427 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
ID: 17856283

try calling

detagridview.endedit

method before you call your update procedure
0
 

Author Comment

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

Expert Comment

by:appari
ID: 17856324
did you try

datagridview.update method?
0
 

Author Comment

by:adwooley2
ID: 17856327
I'll try this out after I get home (I'm working in Japan, so the night is young).
See you again.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 39

Expert Comment

by:appari
ID: 17856338

really:),  me too working in Japan

0
 
LVL 39

Expert Comment

by:appari
ID: 17856344

no jangyou?
0
 
LVL 34

Accepted Solution

by:
Sancler earned 200 total points
ID: 17856901
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
ID: 17857053
Sancler,
EndCurrentEdit did the magic.  Thank you very much!

ADWooley
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

862 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

30 Experts available now in Live!

Get 1:1 Help Now