473,666 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form close changes notification and databinding

TonFrere
14 New Member
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 "TextChange d" 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 1520
Plater
7,872 Recognized Expert Expert
What controls do you need it for besides textbox?
"TextChange d" seemed like a good place for it?
Nov 13 '07 #2
TonFrere
14 New Member
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?
"TextChange d" seemed like a good place for it?
Nov 13 '07 #3
TonFrere
14 New Member
I can't use "TextChange d" 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 Recognized Expert Expert
I can't use "TextChange d" 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
TonFrere
14 New Member
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 "TextChange d" 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
TonFrere
14 New Member
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
2098
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: foreach(MyForm form in AllMyForms){ form.Close(); } Application.Exit(); The OnClosing method is overridden in MyForm. If the user has made changes to his form, this method asks him if he'd like to: a) save his changes b) forget changes...
2
3862
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 with that stuff... However, as somebody out there probably knows, programmatically setting the DateTimePicker.Value property to a new VALUE does NOT in itself constitute a CHANGE to
2
4988
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 reason might be that the user answered "No" when the form's OnClosing() override asked him "Are you sure you want to close this form?"
5
11354
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 changes that have been made. In MFC/Win32, you'd trap the WM_COMMAND/EN_CHANGE notification messages, etc. But, this doesn't seem to happen in Windows Forms. I tried Spy-ing a windows forms app, and the WM_COMMAND messages don't even get sent...
4
6318
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) { RegisterClientScriptBlock("GetData","<Script>close()</Script>"); } But when this runs the browser puts up a dialog box saying: "The web page you are viewing is trying to close the window, od you want to close this window?"
6
1220
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 name is displayed and can be edited. Last Name: Text box where last name is displayed and can be edited. At the end of this list, I want to have two buttons, update and cancel.
6
1553
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 different record. In addition some of the databound controls need to be modified (ie: verified) based on the values of other databound controls. For example, if one checkbox is checked, then I need to ensure that another databound control has a certain...
9
1728
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. The issue is that the user will go to the web to enter and update their information over time, so all the questions need to be on one form. I believe the proper structure for the table would be: MarketingRequest
15
4760
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 the FSW.Changed FileSystemEventhandler, I called the Show method 'frmMain.Show( )' on my form, the form appears but not completely painted and it appears to be hanging with the hourglass.
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8352
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
8863
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...
0
8636
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
7378
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
6189
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
5661
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
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.