Solved

Datagridview - updating problems

Posted on 2006-11-01
8
432 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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 …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

739 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