Datagrid and dataset 'haschanges' problem

  • Thread starter Thread starter thead01
  • Start date Start date
T

thead01

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.
 
Thread,

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

I hope this helps,

Cor
 
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
 
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:
 
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").EndCurrentEdit()

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
 
Back
Top