472,347 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,347 software developers and data experts.

BindingSource / DataSet / DataTable - Event when changed

..Net 2.0
VStudio 2005
C#

I know this is going to seem like a strange question, as even I am sure I
have missed something - but I cant find it.

I want a simple event on any of the objects (BindingSource, DataSet,
DataTable) that fires when data in a bound control changes.

Eg someone types something, or they change the value in a pull down list etc
etc.

I want this so I can then fire the Enabled functions of my buttons (save
etc) so users only press them when needed.

Please let me I have missed something very simple. I have tried all the
events on the BindingSource but with no success.

Regards,

Daniel Jeffrey

Dec 17 '07 #1
1 7953
Hi Daniel,

The underlying data fires this event. DataTable should fire
RowChanging/RowChanged. In case of business object you need to fire it
yourself by implementing the INotifyPropertyChanged interface and fire
PropertyChanged.

The code below demonstrates the use of INotifyPropertyChanged by having the
Enabled property bound to the CanSave property on the business object. For
this binding to work, TextValue needs to fire a PropertyChanged event if it
has changed or the button binding won't get updated.

protected override void OnLoad(EventArgs e)
{
TextBox textBox1 = new TextBox();
Controls.Add(textBox1);

Button button1 = new Button();
button1.Location = new Point(textBox1.Width, 0);
Controls.Add(button1);

BindingSource source = new BindingSource(new BusinessObject(),
"");

textBox1.DataBindings.Add("Text", source, "TextValue", false,
DataSourceUpdateMode.OnPropertyChanged);
button1.DataBindings.Add("Enabled", source, "CanSave");
}
public class BusinessObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

private string _textValue;

public string TextValue
{
get { return _textValue; }
set
{
_textValue = value;
PropertyChanged(this, new
PropertyChangedEventArgs("TextValue"));
}
}

public bool CanSave
{
get
{
if (string.IsNullOrEmpty(TextValue))
return false;
else
return TextValue.Length 3;
}
}
}

--
Happy Coding!
Morten Wennevik [C# MVP]
"Daniel Jeffrey" wrote:
..Net 2.0
VStudio 2005
C#

I know this is going to seem like a strange question, as even I am sure I
have missed something - but I cant find it.

I want a simple event on any of the objects (BindingSource, DataSet,
DataTable) that fires when data in a bound control changes.

Eg someone types something, or they change the value in a pull down list etc
etc.

I want this so I can then fire the Enabled functions of my buttons (save
etc) so users only press them when needed.

Please let me I have missed something very simple. I have tried all the
events on the BindingSource but with no success.

Regards,

Daniel Jeffrey

Dec 17 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Lars Netzel | last post by:
A little background: I use three Datagrids that are in a child parent relation. I Use Negative Autoincrement on the the DataTables and that's...
12
by: Graham Blandford | last post by:
Hi all, Would someone be able to tell me the most 'graceful' way of removing unwanted rows from a dataset based on a condition prior to update?...
1
by: Mike | last post by:
I have the following: 1 x .NET 2.0 .DLL Containing one public DataSet (CustomerHandler) which contains one table and a tableadapter to fill a...
4
by: michael sorens | last post by:
I have successfully bound an XmlDocument to a DataGridView but all fields seem to be strings. I want to retrofit appropriate datatypes on some of ...
2
by: Rob Dob | last post by:
How do I determine if there are any rows within the BindingSource that have changed prior to calling the EndEdit(). I need to do this in order to...
3
by: msnews.microsoft.com | last post by:
Greetings I have a a simple application with 1 form. On my form I use a BindingSource to bind a database table to a "table (gridDataView)" (one...
7
by: Mike | last post by:
i have a small difficulties with BindingSource and dataGridView bind db has properly opened and bind doesn't works. Unfortunately I didn't find any...
5
by: jehugaleahsa | last post by:
Hello: I am sure this question comes up a lot. I need to disable the controls on my Windows forms so that when the BindingSource is empty some...
2
by: Eric B. | last post by:
I could use a little clarification on using a BindingSource with my DataTable. As I understand it, the BindingSource sits between my data source (a...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

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.