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

  • Thread starter Thread starter John
  • Start date Start date
J

John

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
 
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:

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:
 
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
 
Thanks Ryan,

Sorry for the slow response...I shall try this out...looks good...Thank you
so much for spending the time to trial it out for me.

Kind regards
John Sheppard

W.G. Ryan said:
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 said:
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
 
Back
Top