473,691 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Dec 17 '07 #2

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

Similar topics

14
2122
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 workning nice. My problem is when I Update these grid and write to the database and I set the new Primary Keys and related Fields to the new asigned atuonumbers in the Access.
12
1995
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? OR, resetting the rows all to unchanged after they are initally added to the recordset. I create a dataset, which begins empty after the initial .Fill. Then I create several rows with some default information, leaving one
1
8667
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 datatable 1 x .NET 2.0 EXE With a single form containing a DataSet (CustomerHandler1), a BindingSource
4
16731
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 the fields. Let me take this in 2 parts. Part I: I found the ValueType field, leading me to believe that I could say dataGridView.Columns.ValueType = typeof(Double); dataGridView.Columns.ValueType = typeof(Integer); etc.
2
11880
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 archive some records and if I call the EndEdit() then it also wipes out the orginal version of the dataset record with the proposed changes., However I don't wish to iterate through every row in the dataset in order to figure out changes, Does the BindingSource not have something similar to the...
3
23072
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 in the database, one on my form, 2 different types of tables). I want to remove the current row I tried : GrantsBindingSource.RemoveCurrent();
7
13447
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 good example how to connect MS Access with dataGridView and BindSource class. Maybe something like this: DataTable dtResult = new DataTable(); dtResult = GetData(); // this line returns a error GetData doesn't exists!
5
4935
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 the controls bound to it will be disabled. This will make it clear to the user that they have to create a new item first before they start working. This needs to be an easy process because there are many, many forms.
2
16836
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 DataTable) and DataGridView and any changes made to it is reflected in the other two? Now if that is so, how should I access the elements of my DataTable? I need to make decisions on what Rows to remove based on comparing the values of the elements. Should I access the individual elements via...
0
8535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9079
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8793
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8796
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6457
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5817
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4322
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2234
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.