473,503 Members | 2,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Implement "form.dirty" feature on a VB .NET Form

Hi,

I need to implement a "form.dirty" feature on a VB .NET form not
related to a database. I need to know if any of the items (Textboxes,
combo, listboxes, ...) was changed. Is there a quick and easy way to
do this?

Thanks in advance.

Alain
Nov 20 '05 #1
5 4343
Hi Alain,

I am sure you get more answers which say

"have a look at the hashtable"

http://msdn.microsoft.com/library/de...ClassTopic.asp

I hope this helps?

Cor
Nov 20 '05 #2
Alain,
I would add a handler for each controls "Changed" event to a single event
Handler that set a Dirty field.

Something like
Public Class MainForm

Private WithEvents TextBox1 As TextBox
Private WithEvents TextBox2 As TextBox
Private WithEvents ComboBox1 As ComboBox
Private WithEvents ListBox1 As ListBox

Private m_dirty As Boolean

Private Sub Form_Changed(ByVal sender As Object, _
ByVal e As EventArgs) _
Handles TextBox1.TextChanged, TextBox2.TextChanged, _
ComboBox1.SelectedValueChanged, ComboBox1.TextChanged _
ListBox1.SelectValueChanged
m_dirty = True
End Sub

Private Sub TextBox1_Changed(ByVal sender As Object, _
ByVal e As EventArgs) Handles TextBox1.TextChanged
End Sub

End Class

Remember that a single event handler can handle multiple events, plus a
single event can be handled by multiple handlers.

An alternative method to the above is to set the Dirty flag in each of the
individual handlers for each control individually.

Hope this helps
Jay

"Alain Filiatrault" <al****@humaprise.com> wrote in message
news:45**************************@posting.google.c om...
Hi,

I need to implement a "form.dirty" feature on a VB .NET form not
related to a database. I need to know if any of the items (Textboxes,
combo, listboxes, ...) was changed. Is there a quick and easy way to
do this?

Thanks in advance.

Alain

Nov 20 '05 #3
On Thu, 20 May 2004 08:12:55 -0500, Jay B. Harlow [MVP - Outlook] wrote:
Alain,
I would add a handler for each controls "Changed" event to a single event
Handler that set a Dirty field.

Something like
Public Class MainForm

Private WithEvents TextBox1 As TextBox
Private WithEvents TextBox2 As TextBox
Private WithEvents ComboBox1 As ComboBox
Private WithEvents ListBox1 As ListBox

Private m_dirty As Boolean

Private Sub Form_Changed(ByVal sender As Object, _
ByVal e As EventArgs) _
Handles TextBox1.TextChanged, TextBox2.TextChanged, _
ComboBox1.SelectedValueChanged, ComboBox1.TextChanged _
ListBox1.SelectValueChanged
m_dirty = True
End Sub

Private Sub TextBox1_Changed(ByVal sender As Object, _
ByVal e As EventArgs) Handles TextBox1.TextChanged
End Sub

End Class

Remember that a single event handler can handle multiple events, plus a
single event can be handled by multiple handlers.

An alternative method to the above is to set the Dirty flag in each of the
individual handlers for each control individually.

Hope this helps
Jay

Jay, what is the order of the event handlers? Will the TextBox1_Changed
occur first? Or will the Form_Changed occur first? Correct me if I'm
wrong, but if you use AddHandler to wire up the events, the order the
handlers are called will be the order in which they were wired up (FIFO).
Is that correct? But what is the order when using the handles clause?

My follow up question is: If the value in the text box after any text is
typed is the same as the previous value, it may not be necessary to mark
the form as "Dirty". How can you cancel or prevent the Form_Changed
handler from being called? Or is it even possible?
--
Chris

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 20 '05 #4
Chris,
what is the order of the event handlers? Will the TextBox1_Changed
occur first? Or will the Form_Changed occur first? Correct me if I'm Does it really matter what the order is? I really don't know what the order
is, nor do I really care.

If the order is important, I would not use WithEvents, I would use
AddHandler itself.
My follow up question is: If the value in the text box after any text is
typed is the same as the previous value, it may not be necessary to mark
the form as "Dirty". How can you cancel or prevent the Form_Changed
handler from being called? Or is it even possible? Check the definition TextBox.TextChanged event, it is called for each
character typed, if you start with "Help", then type "Help" you will see the
changed event 4 times!

Remember the Changed event suggests that it already occurred, so you cannot
prevent it, you would need to stop the Changing event, however I do not see
that a cancelable TextBox.TextChanging event (you know like the Form.Closing
& Form.Closed events). You could possible do something with the keyboard
events...

Hope this helps
Jay
"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcglobal[dot]]net"> wrote in
message news:1d*****************************@40tude.net... On Thu, 20 May 2004 08:12:55 -0500, Jay B. Harlow [MVP - Outlook] wrote:
Alain,
I would add a handler for each controls "Changed" event to a single event Handler that set a Dirty field.

Something like
Public Class MainForm

Private WithEvents TextBox1 As TextBox
Private WithEvents TextBox2 As TextBox
Private WithEvents ComboBox1 As ComboBox
Private WithEvents ListBox1 As ListBox

Private m_dirty As Boolean

Private Sub Form_Changed(ByVal sender As Object, _
ByVal e As EventArgs) _
Handles TextBox1.TextChanged, TextBox2.TextChanged, _
ComboBox1.SelectedValueChanged, ComboBox1.TextChanged _
ListBox1.SelectValueChanged
m_dirty = True
End Sub

Private Sub TextBox1_Changed(ByVal sender As Object, _
ByVal e As EventArgs) Handles TextBox1.TextChanged
End Sub

End Class

Remember that a single event handler can handle multiple events, plus a
single event can be handled by multiple handlers.

An alternative method to the above is to set the Dirty flag in each of the individual handlers for each control individually.

Hope this helps
Jay

Jay, what is the order of the event handlers? Will the TextBox1_Changed
occur first? Or will the Form_Changed occur first? Correct me if I'm
wrong, but if you use AddHandler to wire up the events, the order the
handlers are called will be the order in which they were wired up (FIFO).
Is that correct? But what is the order when using the handles clause?

My follow up question is: If the value in the text box after any text is
typed is the same as the previous value, it may not be necessary to mark
the form as "Dirty". How can you cancel or prevent the Form_Changed
handler from being called? Or is it even possible?
--
Chris

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.

Nov 20 '05 #5
Chris,
what is the order of the event handlers? Will the TextBox1_Changed
occur first? Or will the Form_Changed occur first? Correct me if I'm Does it really matter what the order is? I really don't know what the order
is, nor do I really care.

If the order is important, I would not use WithEvents, I would use
AddHandler itself.
My follow up question is: If the value in the text box after any text is
typed is the same as the previous value, it may not be necessary to mark
the form as "Dirty". How can you cancel or prevent the Form_Changed
handler from being called? Or is it even possible? Check the definition TextBox.TextChanged event, it is called for each
character typed, if you start with "Help", then type "Help" you will see the
changed event 4 times!

Remember the Changed event suggests that it already occurred, so you cannot
prevent it, you would need to stop the Changing event, however I do not see
that a cancelable TextBox.TextChanging event (you know like the Form.Closing
& Form.Closed events). You could possible do something with the keyboard
events...

Hope this helps
Jay
"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcglobal[dot]]net"> wrote in
message news:1d*****************************@40tude.net... On Thu, 20 May 2004 08:12:55 -0500, Jay B. Harlow [MVP - Outlook] wrote:
Alain,
I would add a handler for each controls "Changed" event to a single event Handler that set a Dirty field.

Something like
Public Class MainForm

Private WithEvents TextBox1 As TextBox
Private WithEvents TextBox2 As TextBox
Private WithEvents ComboBox1 As ComboBox
Private WithEvents ListBox1 As ListBox

Private m_dirty As Boolean

Private Sub Form_Changed(ByVal sender As Object, _
ByVal e As EventArgs) _
Handles TextBox1.TextChanged, TextBox2.TextChanged, _
ComboBox1.SelectedValueChanged, ComboBox1.TextChanged _
ListBox1.SelectValueChanged
m_dirty = True
End Sub

Private Sub TextBox1_Changed(ByVal sender As Object, _
ByVal e As EventArgs) Handles TextBox1.TextChanged
End Sub

End Class

Remember that a single event handler can handle multiple events, plus a
single event can be handled by multiple handlers.

An alternative method to the above is to set the Dirty flag in each of the individual handlers for each control individually.

Hope this helps
Jay

Jay, what is the order of the event handlers? Will the TextBox1_Changed
occur first? Or will the Form_Changed occur first? Correct me if I'm
wrong, but if you use AddHandler to wire up the events, the order the
handlers are called will be the order in which they were wired up (FIFO).
Is that correct? But what is the order when using the handles clause?

My follow up question is: If the value in the text box after any text is
typed is the same as the previous value, it may not be necessary to mark
the form as "Dirty". How can you cancel or prevent the Form_Changed
handler from being called? Or is it even possible?
--
Chris

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.

Nov 20 '05 #6

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

Similar topics

2
17731
by: John Davis | last post by:
I want to know what's the differences between Request.Form("Field Name") and Request.QueryString("Field Name") OR they function exactly the same, which is to return the value of the field?? ...
3
4214
by: Hodad | last post by:
I would like to adapt, as much as possible, the appearance and color red of the font in this button: <P><CENTER><BUTTON VALUE="SUBMIT"><A...
3
2674
by: Pavils Jurjans | last post by:
Hello, I have bumped upon this problem: I do some client-side form processing with JavaScript, and for this I loop over all the forms in the document. In order to identify them, I read their...
2
3586
by: nutthatch | last post by:
I want to be able to import an Excel spreadsheet into Access 2K using the macro command Transferspreadsheet. However, the file I am importing (over which I have no control) contains some records...
9
21469
by: Dan | last post by:
I am trying to use Request.Form("__EVENTTARGET") to get the name of the control that caused a post back. It keeps returning "". I am not really sure why, this happens for all of my controls...
7
2927
by: Mitchell Vincent | last post by:
I've been trying to get a standard toolbar to play nice with some nice icons that I have. When I put them on a button or anything they look perfect, but through an imagelist and on a toolbar they...
7
1933
by: Rich | last post by:
Hi, I was experimenting with some basic sample asp code but can't get it to work correctly: this is bgselector.asp which works OK - you add the name of a basic color like blue, green, yellow...
38
3245
by: Sanders Kaufman | last post by:
I'm converting my table-based layouts to css-positioned divs - but the ONLY reason I'm doing it is because it's *considered* a best practice. I don't really see where anything goes hinky when...
3
1892
by: eBob.com | last post by:
How does a "sub-form", i.e. one invoked by another form, determine anything about the form which brought it into existence, i.e., I suppose, instantiated it? I wanted to so something like this ......
0
7207
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,...
0
7093
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
7291
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
7357
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
7468
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
5598
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,...
1
5023
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...
0
4690
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...
0
3180
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...

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.