Can I bind a control to a dataset.haschanges property?

Can I bind a control to a dataset.haschanges property?

am 05.12.2007 12:03:30 von DFS

Hello,

I was wondering if it was possibly to bind a control to a dataset.haschanges
property.

The reason I want to do this is so that a little warning shows up on the
form saying that the record has not been saved.

Thank you heaps for anyones thoughts
John Sheppard

Re: Can I bind a control to a dataset.haschanges property?

am 05.12.2007 20:28:32 von WilliamRyan

Well, not directly. HasChanges is a method not a property so while it seems
pedantic, it is the reason it won't work. If you really needed thsi
functionality, you could create a property that simply wrapped the call to
HasChanges and bind to it instead but it would need to be subclassed. (note,
I have not specifically done this but since you can bind to other
properites, I'm 99.9% sure you'd be fine if you created a property of your
own.)
"John" wrote in message
news:fj60ok02jn0@news5.newsguy.com...
> Hello,
>
> I was wondering if it was possibly to bind a control to a
> dataset.haschanges property.
>
> The reason I want to do this is so that a little warning shows up on the
> form saying that the record has not been saved.
>
> Thank you heaps for anyones thoughts
> John Sheppard
>

Re: Can I bind a control to a dataset.haschanges property?

am 05.12.2007 20:33:33 von WilliamRyan

John:

I just went ahead and did it...
For the whole "Untyped" thing, you can just deal with this class like you
would any other dataset and if you created a typed dataset you could do the
same:

namespace WindowsApplication2

{

public class AugmentedDataSet : DataSet

{

private Boolean hasChanged;

public Boolean HasChanged

{

get { return base.HasChanges(); }

set { hasChanged = value; }

}


}

}



Now here's the binding code:



"John" wrote in message
news:fj60ok02jn0@news5.newsguy.com...
> Hello,
>
> I was wondering if it was possibly to bind a control to a
> dataset.haschanges property.
>
> The reason I want to do this is so that a little warning shows up on the
> form saying that the record has not been saved.
>
> Thank you heaps for anyones thoughts
> John Sheppard
>

Re: Can I bind a control to a dataset.haschanges property?

am 05.12.2007 20:33:54 von WilliamRyan

Ooops, I think I forgot to send this

private void Form1_Load(object sender, EventArgs e)

{

AugmentedDataSet ds = new AugmentedDataSet();


ds.Tables.Add(new DataTable("WhateverTable"));

ds.Tables[0].Columns.Add(new DataColumn("MyColumn", typeof(String)));

chkHasChanges.DataBindings.Add("Checked", ds.HasChanged, null);

}



Coupled with my last post, this should do it for you

"John" wrote in message
news:fj60ok02jn0@news5.newsguy.com...
> Hello,
>
> I was wondering if it was possibly to bind a control to a
> dataset.haschanges property.
>
> The reason I want to do this is so that a little warning shows up on the
> form saying that the record has not been saved.
>
> Thank you heaps for anyones thoughts
> John Sheppard
>