BindingSource / DataSet / DataTable - Event when changed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel Jeffrey

    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

  • =?Utf-8?B?TW9ydGVuIFdlbm5ldmlrIFtDIyBNVlBd?=

    #2
    RE: BindingSource / DataSet / DataTable - Event when changed

    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 INotifyProperty Changed interface and fire
    PropertyChanged .

    The code below demonstrates the use of INotifyProperty Changed 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(EventArg s e)
    {
    TextBox textBox1 = new TextBox();
    Controls.Add(te xtBox1);

    Button button1 = new Button();
    button1.Locatio n = new Point(textBox1. Width, 0);
    Controls.Add(bu tton1);

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

    textBox1.DataBi ndings.Add("Tex t", source, "TextValue" , false,
    DataSourceUpdat eMode.OnPropert yChanged);
    button1.DataBin dings.Add("Enab led", source, "CanSave");
    }


    public class BusinessObject : INotifyProperty Changed
    {
    public event PropertyChanged EventHandler PropertyChanged ;

    private string _textValue;

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

    public bool CanSave
    {
    get
    {
    if (string.IsNullO rEmpty(TextValu e))
    return false;
    else
    return TextValue.Lengt h 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
    >
    >

    Comment

    Working...