By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,685 Members | 1,796 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,685 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.