Solved

Datagridview - updating problems

Posted on 2006-11-01
8
434 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

628 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