Newbie: Is it possible to create an EventHandler for DataSet.HasChanges()?

  • Thread starter Thread starter nvx
  • Start date Start date
N

nvx

Hi,
I'm new to C# so please tell me in case this is completely wrong... I need to catch the change of DataSet.HasChanges() to
indicate that data has been modified in any databound control. If this is possible to code, please, add some sample code. Maybe
I could catch changes in all these databound controls, but I'd like to do it the previous way.

Thanks in advance.

With regards
nvx
 
Not sure about that, maybe you could create your own version of DataSet that
inherited from the standard one and add your own event.

But could you use the ColumnChanged and/or RowChanged events of the
DataTables within the DataSet?

myDataSet.Tables[0].ColumnChanged

Cheers,

Chris.

PS.
A fairly rubbish possibility (if its in a form) is to use a Timer that
checks the HasChanges property on a regular basis, and acts if it changes...
:-/
 
Hi Chris,
thank you for your response. As I'm quite a newbie I surely won't create my own version of DataSet and probably use the
dataSet.Tables[...].RowChanged...

Have a nice day...

nvx


ChrisM napsal(a):
Not sure about that, maybe you could create your own version of DataSet that
inherited from the standard one and add your own event.

But could you use the ColumnChanged and/or RowChanged events of the
DataTables within the DataSet?

myDataSet.Tables[0].ColumnChanged

Cheers,

Chris.

PS.
A fairly rubbish possibility (if its in a form) is to use a Timer that
checks the HasChanges property on a regular basis, and acts if it changes...
:-/



nvx said:
Hi,
I'm new to C# so please tell me in case this is completely wrong... I need
to catch the change of DataSet.HasChanges() to
indicate that data has been modified in any databound control. If this is
possible to code, please, add some sample code. Maybe
I could catch changes in all these databound controls, but I'd like to do
it the previous way.

Thanks in advance.

With regards
nvx
 
nvx,

You can use the CurrencyManager for this data source. There you can hook on
an event that will notify you whenever the given data source has been
changed regardless of the control used to change it (in a case where more
than one control is bound to the same datasource).

Your code should look something like this.

In my sample application I did the databinding in the designer, so I put my
code for hooking the event in the constructor after InitiazlizeComponent
call (at this point all databinding is set up.

static int i;

public Form1()
{

InitializeComponent();
((CurrencyManager)this.BindingContext[this.dataSource]).ItemChanged
+= new ItemChangedEventHandler(Form1_ItemChanged);

}

void Form1_ItemChanged(object sender, ItemChangedEventArgs e)
{
Console.WriteLine("{0}.Changed", i++);
}


For more information on how databinding works in winforms read the articles
here:
http://msdn.microsoft.com/library/d...on/html/vboriWindowsFormsDataArchitecture.asp


--
HTH
Stoitcho Goutsev (100)



nvx said:
Hi Chris,
thank you for your response. As I'm quite a newbie I surely won't create
my own version of DataSet and probably use the
dataSet.Tables[...].RowChanged...

Have a nice day...

nvx


ChrisM napsal(a):
Not sure about that, maybe you could create your own version of DataSet
that
inherited from the standard one and add your own event.

But could you use the ColumnChanged and/or RowChanged events of the
DataTables within the DataSet?

myDataSet.Tables[0].ColumnChanged

Cheers,

Chris.

PS.
A fairly rubbish possibility (if its in a form) is to use a Timer that
checks the HasChanges property on a regular basis, and acts if it
changes...
:-/



nvx said:
Hi,
I'm new to C# so please tell me in case this is completely wrong... I
need
to catch the change of DataSet.HasChanges() to
indicate that data has been modified in any databound control. If this
is
possible to code, please, add some sample code. Maybe
I could catch changes in all these databound controls, but I'd like to
do
it the previous way.

Thanks in advance.

With regards
nvx
 
Hi,

There is no way to get an event for this.

What you can do is use DataTable events like (RowChanged )

Also take a look at the MVP pattern.
 
Hi Stoitcho,
since I have different controls bound to different tables, I would have to set this up for all tables anyway (every table has
its own DataAdapter etc.). I coded it using the RowChanged event of a DataTable. Nevertheless, thank you very much for your time.

Have a nice day...

nvx


Stoitcho Goutsev (100) napsal(a):
 
Hi Ignacio,
thank you for your reply. I've already coded it using the RowChanged event.

With regards
nvx


Ignacio Machin ( .NET/ C# MVP ) napsal(a):
 
Hi,

Just keep in mind that you may have 20 tables with 200 controls bound to
them. Using the Currency manager you need to hook on 20 events vs 200. I
don't know details about your project, but just keep in mind this.


--
Stoitcho Goutsev (100)
nvx said:
Hi Stoitcho,
since I have different controls bound to different tables, I would have to
set this up for all tables anyway (every table has
its own DataAdapter etc.). I coded it using the RowChanged event of a
DataTable. Nevertheless, thank you very much for your time.

Have a nice day...

nvx


Stoitcho Goutsev (100) napsal(a):
nvx,

You can use the CurrencyManager for this data source. There you can hook
on
an event that will notify you whenever the given data source has been
changed regardless of the control used to change it (in a case where more
than one control is bound to the same datasource).

Your code should look something like this.

In my sample application I did the databinding in the designer, so I put
my
code for hooking the event in the constructor after InitiazlizeComponent
call (at this point all databinding is set up.

static int i;

public Form1()
{

InitializeComponent();

((CurrencyManager)this.BindingContext[this.dataSource]).ItemChanged
+= new ItemChangedEventHandler(Form1_ItemChanged);

}

void Form1_ItemChanged(object sender, ItemChangedEventArgs e)
{
Console.WriteLine("{0}.Changed", i++);
}


For more information on how databinding works in winforms read the
articles
here:
http://msdn.microsoft.com/library/d...on/html/vboriWindowsFormsDataArchitecture.asp
 
Back
Top