[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Save record to database when moving row in datagrid

Posted on 2006-03-28
2
Medium Priority
?
185 Views
Last Modified: 2010-04-23
Hello,
Ive got a datagrid bound to a datable. The way im saving the data to database is through a 'save button'. But the users want the record to be saved automatically when they  move to another row or they add a new row without them to have to take action.

I was thinking, to check the state of a row everytime they scroll though the rows, and if that row has changes then, save it. BUt im not sure which is the best way to do this.

Any ideas would be helpful!

Thanks!

0
Comment
Question by:arcross
2 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 500 total points
ID: 16308926
You could use the .CellChanged event of the DataGrid itself to check if the Row has changed and, if it has, then check to see if your DataSet .HasChanges and then, if it has, save the changes.  That would be on these lines

    Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
        Static PreviousRow As Integer = -1
        Dim ThisRow As Integer
        ThisRow = DataGrid1.CurrentCell.RowNumber
        If ThisRow <> PreviousRow Then
            If DataSet.HasChanges Then
                DataAdapter.Update(DataTable)
            End If
        End If
        PreviousRow = ThisRow
    End Sub

Alternatively you could declare a CurrencyManager WithEvents, or add an event handler, and use its .PositionChanged event similarly, but without having to record the previous row's number with this row's number, as the event will only fire when the row changes.  On these lines

    Private Sub cm_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cm.PositionChanged
        If DataSet.HasChanges Then
            DataAdapter.Update(DataTable)
        End If
    End Sub

Roger
0
 
LVL 8

Author Comment

by:arcross
ID: 16309164
cheers sancler!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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 …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

834 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