473,466 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 5023
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Michael Dimento | last post by:
I'm trying to detect if there are any unsaved changes in a dataset when a user hits close form button (top right hand corner). My problem is that HasChanges does not detect a row that has been...
6
by: BFX | last post by:
Hi All, I have datagrid with binding on dataset this.grdMachineType.DataMember = "MachineTypes"; this.grdMachineType.DataSource = this.dsMachineTypes; After append new row in datagrid i...
0
by: TK | last post by:
Hi, I need help on datagrid. I have a dataset exposed as a webservice. I do have a web application that is supposed to consume the service on a datagrid.
3
by: matthew schouppe | last post by:
I have a datagrid with two columns, the first a normal bound column, the second is a template column created from a bound column. For the ItemTemplate of the Template Column, I removed the label...
0
by: Geraldine Hobley | last post by:
Hello, I have a problem whereby I have datagrid bound to a dataset with the following properties I have put a similar problem up b4 but I still do not have an answer. MyDatagrid.DataSource =...
6
by: Jan Nielsen | last post by:
Hi I asked this question some weeks ago, but have found no soluion yet, so I try again I have a parent detail relationship between two tables. The detail records are shown in a datagrid...
3
by: Jim | last post by:
I have a datagrid with a DataAdapter as the DataSource. The user fills in their data for 3 columns and I want to programically add a value to the 4th (invisible) column (employee number). That way...
4
by: thead01 | last post by:
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...
3
by: John Sheppard | last post by:
Hello there, I have the following code; I do this as a work around for a dataset.haschanges method which doesnt appear to work correctly either For Each dt As DataTable In myDs.Tables If Not...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.