Datagrid and dataset 'haschanges' problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thead01@gmail.com

    #1

    Datagrid and dataset 'haschanges' problem

    I create a dataset, load xmlfile, create dataview (ds.defaultview ) and
    bind it to a datagrid (dataset haschanges property is now 'true').
    When a user closes the form I want to check via ds.haschanges if there
    are pending changes in the dataset. Now returns 'true' always.
    When I say 'acceptchanges' after loading the xmlfile, the haschanges
    always says 'false' when closing the form.
    Guess I'm missing something. Alternative solution to check for pending
    changes when closing the form is also fine.

  • Cor Ligthert

    #2
    Re: Datagrid and dataset 'haschanges' problem

    Thread,

    No you are missing nothing, acceptchanges mean set all datarows to the
    rowstate unchanged.

    I hope this helps,

    Cor


    Comment

    • AdGerrits@gmail.com

      #3
      Re: Datagrid and dataset 'haschanges' problem

      Okay, let's try to make my problem clear. Here are the form load en
      close events. Reason I use a dataview is that I won't allow the user to
      add a new record.
      My problem is that using 'haschanges' is not reliable for the purpose I
      use it for.

      Private Sub frmEditOptions_ Load(ByVal sender As System.Object,
      ByVal e As System.EventArg s) Handles MyBase.Load
      ds1.ReadXml(gst rFile)
      Dim dv As New DataView
      dv = ds1.Tables("Opt ions").DefaultV iew()
      dv.AllowNew = False
      With DataGrid1
      .DataSource = dv
      .CaptionText = "Options"
      End With
      End Sub

      Private Sub frmEditOptions_ Closing(ByVal sender As Object, ByVal e
      As System.Componen tModel.CancelEv entArgs) Handles MyBase.Closing
      Dim s As String
      If ds1.HasChanges( ) Then
      If MsgBox("Wijzigi ngen opslaan?", MsgBoxStyle.Yes No +
      MsgBoxStyle.Que stion) = MsgBoxResult.Ye s Then
      WriteXmlToFile( ds1, gstrFile)
      End If
      End If
      End Sub

      Comment

      • thead01@gmail.com

        #4
        Re: Datagrid and dataset 'haschanges' problem

        Okay, let's try to make my problem clear. Here are the form load en
        close events. Reason I use a dataview is that I won't allow the user to

        add a new record. My problem is that using 'haschanges' is not reliable
        for the purpose I use it for.

        dim ds1 as new dataset
        Private Sub frmEditOptions_ Load(ByVal sender As System.Object,
        ByVal e As System.EventArg s) Handles MyBase.Load
        ds1.ReadXml(gst rFile)
        Dim dv As New DataView
        dv = ds1.Tables("Opt ions").DefaultV ­iew()
        dv.AllowNew = False
        With DataGrid1
        .DataSource = dv
        .CaptionText = "Options"
        End With
        End Sub


        Private Sub frmEditOptions_ Closing(ByVal sender As Object, ByVal e
        As System.Componen tModel.CancelEv ­entArgs) Handles MyBase.Closing
        Dim s As String
        If ds1.HasChanges( ) Then
        If MsgBox("Wijzigi ngen opslaan?", MsgBoxStyle.Yes No +
        MsgBoxStyle.Que stion) = MsgBoxResult.Ye s Then
        WriteXmlToFile( ds1, gstrFile)
        End If
        End If
        End Sub




        Cor Ligthert schreef:[color=blue]
        > Thread,
        >
        > No you are missing nothing, acceptchanges mean set all datarows to the
        > rowstate unchanged.
        >
        > I hope this helps,
        >
        > Cor[/color]

        Comment

        • Cor Ligthert

          #5
          Re: Datagrid and dataset 'haschanges' problem

          Ad,

          I don't see what there is wrong and I see only a small part of your code,
          however probably the last changed row will not be updated, therefore I would
          add something as
          [color=blue]
          > Private Sub frmEditOptions_ Closing(ByVal sender As Object, ByVal e
          > As System.Componen tModel.CancelEv entArgs) Handles MyBase.Closing
          > Dim s As String[/color]

          BindingContext( ds1.Tables("Opt ions").EndCurre ntEdit()
          [color=blue]
          > If ds1.HasChanges( ) Then
          > If MsgBox("Wijzigi ngen opslaan?", MsgBoxStyle.Yes No +
          > MsgBoxStyle.Que stion) = MsgBoxResult.Ye s Then
          > WriteXmlToFile( ds1, gstrFile)
          > End If
          > End If
          > End Sub
          >[/color]

          I hope this helps

          Cor


          Comment

          Working...