473,411 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Form close changes notification and databinding

TonFrere
Hello,
I'm simply trying to keep track of changes on a windows form as users modify control values. I created a boolean variable called IsDirty and want it set to true whenever the user changes something.

The problem is: where to set IsDirty to true?

If I raise the event on "TextChanged" event of a control (let say a textbox), it is set to true whenever the user changes current record.

I also tried to raise it on "Validating" event but then, as soon as I enter a control and leave it, IsDirty is set to true even if the user haven't made any changes.

This was very easy with the DatagridView control since I could add the code to the OnCellEndEdit event.

I bet there's a much easyier way to look for a "row dirtiness" directly on the form (maybe through the bindingsource?).

Any advice?
Thanks a lot,
Justin
Nov 13 '07 #1
6 1507
Plater
7,872 Expert 4TB
What controls do you need it for besides textbox?
"TextChanged" seemed like a good place for it?
Nov 13 '07 #2
Common controls: Combobox, CheckBoxes etc. Is it ok to look it from the control side or should I find a way to check if the bindingsource or dataset are changed?

I'm a little embarrassed to be stock on something that seems so obvious.

Justin

What controls do you need it for besides textbox?
"TextChanged" seemed like a good place for it?
Nov 13 '07 #3
I can't use "TextChanged" because this would be raised each time the user changes record.

Windows Forms, C#, Visual Studio 2005.

Still need help.
Thanks!
Nov 14 '07 #4
Plater
7,872 Expert 4TB
I can't use "TextChanged" because this would be raised each time the user changes record.
Don't you WANT that to happen so you can set isDirty=true?
Nov 14 '07 #5
Sorry, I'll try to describe a little more.

I want IsDirty set to true whenever a user changes a value on the form. This is to track changes (and to advice the user if he leaves without saving).

If I set IsDirty to True in the "TextChanged" event, it happens whenever a user make changes (which is good) but also, whenever a user move between records using the Binding Navigator move next, move previous etc. buttons (which is not good). This happens because the actual value of the control changes from a record to the other (which is perfectly logic) but I can't find an event that would be raised only when a user physically changes the contain of a control.

I also tried adding the event in the "validated" event. But then, as soon as a control gets the focus, IsDirty is set to true (even if the user doesn't make any changes or the control gets the focus "accidentally").

In other words, I want to track only user simply "have made changes"...

I have a feeling I'm doing this the wrong way.

What do you think?
Justin
Nov 14 '07 #6
I think I found the perfect combo to make this work:

- For each control TextChange (or equivalent for other controls) I set IsDirty to True. (Capturing users changes)

- On BindingSource CurrentChanged, I set IsDirty to False. (Because it is set to true when controls are filled with db values.)

- On form OnActivated event, I set IsDirty to false (this way I don't get it set to true after the initial binding is done).

The only trouble with this is that users will not be notified if they have made changes to a record, then move to another, and finally close the form without changing anything. I might as well save changes between record navigation.

It works though... this seems a lot of trouble for such a trivial feature.

Anybody has a better idea?

And is there be a way of adding the "set isdirty to true" feature on all controls on my form (when form load or whatever)? This way, I would make sure that new controls added to the form would have the same feature (Should I override all controls type classes and add the feature to them... is this good or bad pratice?)

Thanks,
Justin
Nov 14 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jules Winfield | last post by:
My WinForms application can have any number of top level forms open at a given time. If the user selects File|Exit, all of the forms are closed. The loop to close the forms looks something like this:...
2
by: Richard | last post by:
Hi, I have a DateTime picker control on a form. The datetime picker control is data bound to a column in a DataTable. Yes I know about bound DateTime pickers and DBNull and etc. so no troubles...
2
by: Chien Lau | last post by:
Hi, At a certain point in my application, I have access to a Form object. I want to close that form: form.Close(); There are any number of reasons why this form might not close. A common...
5
by: Dave | last post by:
How do I check in a Windows Forms app if any controls have changed? I have a form that collects data, and I want to prompt the user if they try to exit the app, or load a new file, without saving...
4
by: Ron Lautmann | last post by:
I want to close a browser window so I created a Close button that does this: private void Button1_Click(object sender, System.EventArgs e) {...
6
by: Joe | last post by:
Hi, I have a MS Access DB in which a record has just too many fields to be able to allow users to do inline editing in a datagrid. So I want to display as First Name: Text box where first...
6
by: JohnR | last post by:
I'm running into a 'timing' or 'race' condition on my form. All textbox controls are bound to a datasource, but certain other controls (like labels) need to be updated when you move to a...
9
by: sck10 | last post by:
Hello, I am building a web form that will be used to gather information for marketing plans. The form will have 15 questions which must be answered. Each question can have large blocks of text....
15
by: Angelo | last post by:
Hi all, I'm using a FileSystemWatcher to monitor a directory. I want the FSW to pop up my already instantiated but invisible form. However, I'm running into some problems with this. 1) In...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...
0
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...

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.