Solved

Datagridview - updating problems

Posted on 2006-11-01
8
433 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
[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
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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
 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

734 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