troubleshooting Question

Saving changes to datagridview

Avatar of wiswalld
wiswalldFlag for United States of America asked on
Visual Basic.NET
8 Comments1 Solution394 ViewsLast Modified:
I have a datagridview on my form that displays available units based on an access query. The access query is based on two tables, one with the available unit information and one with the shift information broken down into three shifts. The shifts are designated with a 1,2 or 3.
1 - 2300-0659
2 - 0700-1459
3 - 1500-2259

This way the form knows what to show based on this in the shift time field of the query
Format(Now(),"h")

My problem I have is I copy the information into a second datagridview which shows the assigned units using this code

Dim dr As DataRow = Me._CAD_050107DataSet.Tables("assignedvehicles").NewRow
        'Put values into row
        dr(1) = EventNumber.Text
        dr(2) = Datagridview1.CurrentRow.Cells(1).Value.ToString
        dr(3) = Datagridview1.CurrentRow.Cells(3).Value.ToString
        dr(4) = Datagridview1.CurrentRow.Cells(4).Value.ToString
        Me.Datagridview1.CurrentRow.Cells(7).Value = "No"
        Me.Datagridview1.CurrentRow.Cells(7).Style.BackColor() = Color.Red



        'and so on, making sure you put values in any ...
        '... fields/columns that do not allow null
        Me._CAD_050107DataSet.Tables("assignedvehicles").Rows.Add(dr)

In doing so I change one of the field values to "No" and the background to red.
Me.Datagridview1.CurrentRow.Cells(7).Value = "No"
        Me.Datagridview1.CurrentRow.Cells(7).Style.BackColor() = Color.Red

This works, but I have a timer on the form that refreshes the datagridview every minute because it is being used as a front end. When it refreshes it changes the "No" nack to "Yes"

I guess my real question is how do I save changes to the tableadapter when I run this code so it stays as "No". I have code later that will change back to "Yes".

I have tried something like

Me.Validate()
        Me.QueryShiftStatusBindingSource.EndEdit()
        Me.Datagridview2.EndEdit()
        Me.QueryShiftStatusTableAdapter.Update(Me._CAD_050107DataSet.QueryShiftStatus)


*****Update is not a member ..........******
ASKER CERTIFIED SOLUTION
Sancler

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros