469,643 Members | 1,257 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

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 7532
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Graham Blandford | last post: by
3 posts views Thread by msnews.microsoft.com | last post: by
5 posts views Thread by jehugaleahsa | last post: by
2 posts views Thread by Eric B. | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.