471,348 Members | 1,880 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

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.

Jul 21 '05 #1
4 4910
Thread,

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

I hope this helps,

Cor
Jul 21 '05 #2
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.EventArgs) Handles MyBase.Load
ds1.ReadXml(gstrFile)
Dim dv As New DataView
dv = ds1.Tables("Options").DefaultView()
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.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Dim s As String
If ds1.HasChanges() Then
If MsgBox("Wijzigingen opslaan?", MsgBoxStyle.YesNo +
MsgBoxStyle.Question) = MsgBoxResult.Yes Then
WriteXmlToFile(ds1, gstrFile)
End If
End If
End Sub

Jul 21 '05 #3
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.EventArgs) Handles MyBase.Load
ds1.ReadXml(gstrFile)
Dim dv As New DataView
dv = ds1.Tables("Options").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.ComponentModel.CancelEv*entArgs) Handles MyBase.Closing
Dim s As String
If ds1.HasChanges() Then
If MsgBox("Wijzigingen opslaan?", MsgBoxStyle.YesNo +
MsgBoxStyle.Question) = MsgBoxResult.Yes Then
WriteXmlToFile(ds1, gstrFile)
End If
End If
End Sub


Cor Ligthert schreef:
Thread,

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

I hope this helps,

Cor


Jul 21 '05 #4
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
Private Sub frmEditOptions_Closing(ByVal sender As Object, ByVal e
As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Dim s As String
BindingContext(ds1.Tables("Options").EndCurrentEdi t()
If ds1.HasChanges() Then
If MsgBox("Wijzigingen opslaan?", MsgBoxStyle.YesNo +
MsgBoxStyle.Question) = MsgBoxResult.Yes Then
WriteXmlToFile(ds1, gstrFile)
End If
End If
End Sub


I hope this helps

Cor
Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Michael Dimento | last post: by
6 posts views Thread by BFX | last post: by
reply views Thread by Geraldine Hobley | last post: by
6 posts views Thread by Jan Nielsen | last post: by
3 posts views Thread by John Sheppard | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.