DataTable GetChanges Issue

6 posts, 1 answers
  1. Gérald
    Gérald avatar
    8 posts
    Member since:
    Dec 2010

    Posted 15 Mar 2011 Link to this post

    Hi,

    I have a problem using datatable.getChanges method with a radGridView binded on a datatable, changing values programmaticaly:
    The first changed value is not in the datatable.getChanges results.

    Here is a simple example :

    Designer.vb
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Partial Class testTelerik
        Inherits System.Windows.Forms.Form
      
        'Form remplace la méthode Dispose pour nettoyer la liste des composants.
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            Try
                If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
                End If
            Finally
                MyBase.Dispose(disposing)
            End Try
        End Sub
      
        'Requise par le Concepteur Windows Form
        Private components As System.ComponentModel.IContainer
      
        'REMARQUE : la procédure suivante est requise par le Concepteur Windows Form
        'Elle peut être modifiée à l'aide du Concepteur Windows Form.  
        'Ne la modifiez pas à l'aide de l'éditeur de code.
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Dim GridViewTextBoxColumn1 As Telerik.WinControls.UI.GridViewTextBoxColumn = New Telerik.WinControls.UI.GridViewTextBoxColumn()
            Me.RadGridView1 = New Telerik.WinControls.UI.RadGridView()
            Me.RadButton1 = New Telerik.WinControls.UI.RadButton()
            CType(Me.RadGridView1, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.RadButton1, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'RadGridView1
            '
            Me.RadGridView1.Location = New System.Drawing.Point(27, 34)
            '
            'RadGridView1
            '
            Me.RadGridView1.MasterTemplate.AllowAddNewRow = False
            Me.RadGridView1.MasterTemplate.AllowDeleteRow = False
            Me.RadGridView1.MasterTemplate.AllowEditRow = False
            Me.RadGridView1.MasterTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill
            GridViewTextBoxColumn1.FieldName = "Name"
            GridViewTextBoxColumn1.FormatString = ""
            GridViewTextBoxColumn1.HeaderText = "Name"
            GridViewTextBoxColumn1.Name = "column1"
            GridViewTextBoxColumn1.Width = 219
            Me.RadGridView1.MasterTemplate.Columns.AddRange(New Telerik.WinControls.UI.GridViewDataColumn() {GridViewTextBoxColumn1})
            Me.RadGridView1.Name = "RadGridView1"
            Me.RadGridView1.Size = New System.Drawing.Size(240, 150)
            Me.RadGridView1.TabIndex = 0
            Me.RadGridView1.Text = "RadGridView1"
            '
            'RadButton1
            '
            Me.RadButton1.Location = New System.Drawing.Point(137, 212)
            Me.RadButton1.Name = "RadButton1"
            Me.RadButton1.Size = New System.Drawing.Size(130, 24)
            Me.RadButton1.TabIndex = 1
            Me.RadButton1.Text = "RadButton1"
            '
            'testTelerik
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(292, 266)
            Me.Controls.Add(Me.RadButton1)
            Me.Controls.Add(Me.RadGridView1)
            Me.Name = "testTelerik"
            Me.Text = "testTelerik"
            CType(Me.RadGridView1, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.RadButton1, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)
      
        End Sub
        Friend WithEvents RadGridView1 As Telerik.WinControls.UI.RadGridView
        Friend WithEvents RadButton1 As Telerik.WinControls.UI.RadButton
    End Class

    Form.vb
    Public Class testTelerik
        Public Sub New()
      
            ' Cet appel est requis par le concepteur.
            InitializeComponent()
      
            Dim dt As New DataTable
            dt.Columns.Add("Name", GetType(String))
            Dim dr As DataRow = dt.NewRow
            dr("Name") = "Johnson"
            dt.Rows.Add(dr)
            dr = dt.NewRow
            dr("Name") = "Peter"
            dt.Rows.Add(dr)
            dt.AcceptChanges()
            RadGridView1.DataSource = dt
        End Sub
      
      
        Private Sub RadButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton1.Click
            Dim dt As DataTable = DirectCast(RadGridView1.DataSource, DataTable)
            RadGridView1.Rows(0).Cells(0).Value = "NewOne"
            RadGridView1.Rows(1).Cells(0).Value = "NewOne2"
            Dim changes As DataTable = dt.GetChanges
            MessageBox.Show(changes.Rows.Count.ToString + " change(s)")
        End Sub
    End Class

    I expect 2 changes whereas i have only 1..

    Is this a bug ?
    Is there a workaround?

    Thanks,
    Gerald
  2. Answer
    Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 18 Mar 2011 Link to this post

    Hello Gérald,

    Thank you for your sample code.

    Actually, the described behavior is expected, because the last edited value keeps the data bound object in editing state and changes are not confirmed in the underlying data source. To commit the values, you have to call EndEdit method for every bound object, which was edited. Please consider the following code:
    Dim dt As DataTable = DirectCast(RadGridView1.DataSource, DataTable)
    RadGridView1.Rows(0).Cells(0).Value = "NewOne"
    Dim obj As IEditableObject = RadGridView1.Rows(0).DataBoundItem
    obj.EndEdit()
    RadGridView1.Rows(1).Cells(0).Value = "NewOne2"
    obj = RadGridView1.Rows(1).DataBoundItem
    obj.EndEdit()
    Dim changes As DataTable = dt.GetChanges

    I hope this helps. Let me know if you have any additional questions.

    Greetings,
    Martin Vasilev
    the Telerik team
  3. Gérald
    Gérald avatar
    8 posts
    Member since:
    Dec 2010

    Posted 29 Mar 2011 Link to this post

    It's exactly what I needed..

    Thank you,
    Gérald

  4. ali
    ali avatar
    1 posts
    Member since:
    May 2011

    Posted 09 May 2011 Link to this post

    hello Gérald
    basically i want to do the same but in c# , can u help me to understand what should i do to get the latest changes from db and display into grid via programing.

    background of my application is i am making some forex online system and want to display real time data into gird

    please help

    regards
    Ali
  5. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 12 May 2011 Link to this post

    Hi Gérald,

    Thank you for writing.

    You can find a lot of info about data-binding in Windows Forms in the MSDN Library. In regards to the C# code, you can easily convert the code from this topic, by using the online code convertor tool.

    Let me know if you have any additional questions.

    Kind regards,
    Martin Vasilev
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  6. Irina
    Irina avatar
    1 posts
    Member since:
    Nov 2011

    Posted 15 Nov 2011 Link to this post

    Thank you so much for your help Martin!
    It works for me now!

    Irina N.,
Back to Top