PC Review


Reply
Thread Tools Rate Thread

"dirty" flag on a form

 
 
aussie rules
Guest
Posts: n/a
 
      22nd May 2004
Hi,

I have some really, really large forms with dozens of text boxs.

What I want to do is somehow know that the user has edited a text box, so
that if they close the form, i can ask them if they would like to save there
changes.

Is there a simple way to do this, or do I have to have code in each text
boxes keypress(?) event ?

Thanks



 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      22nd May 2004
Hi Aussie,

Why not just make a loop through all your texboxes before closing to see it
there is entered something.

Very easy to do in my opinion.

Or do I not understand you?

Cor


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      22nd May 2004
* "aussie rules" <(E-Mail Removed)> scripsit:
> What I want to do is somehow know that the user has edited a text box, so
> that if they close the form, i can ask them if they would like to save there
> changes.


\\\
Private m_Dirty As Boolean
..
..
..
Public Sub TextBox_TextChanged( _
ByVal sender As Object, _
... _
) _
Handles Me.TextBox1.TextChanged, Me.TextBox2.TextChanged, ...
If DirectCast(sender, TextBox).TextLength > 0 Then
m_Dirty = True
End If
End Sub
..
..
..
If m_Dirty Then
...
Else
...
End If
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
Ray Cassick \(Home\)
Guest
Posts: n/a
 
      22nd May 2004
I think maybe this is a good example of where an extender control might come
into play...


"Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> * "aussie rules" <(E-Mail Removed)> scripsit:
> > What I want to do is somehow know that the user has edited a text box,

so
> > that if they close the form, i can ask them if they would like to save

there
> > changes.

>
> \\\
> Private m_Dirty As Boolean
> .
> .
> .
> Public Sub TextBox_TextChanged( _
> ByVal sender As Object, _
> ... _
> ) _
> Handles Me.TextBox1.TextChanged, Me.TextBox2.TextChanged, ...
> If DirectCast(sender, TextBox).TextLength > 0 Then
> m_Dirty = True
> End If
> End Sub
> .
> .
> .
> If m_Dirty Then
> ...
> Else
> ...
> End If
> ///
>
> --
> Herfried K. Wagner [MVP]
> <URL:http://dotnet.mvps.org/>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      22nd May 2004
Hi Ray,

No an example how to do simple things in a difficult way.

Cor

> > \\\
> > Private m_Dirty As Boolean
> > .
> > .
> > .
> > Public Sub TextBox_TextChanged( _
> > ByVal sender As Object, _
> > ... _
> > ) _
> > Handles Me.TextBox1.TextChanged, Me.TextBox2.TextChanged, ...
> > If DirectCast(sender, TextBox).TextLength > 0 Then
> > m_Dirty = True
> > End If
> > End Sub
> > .
> > .
> > .
> > If m_Dirty Then
> > ...
> > Else
> > ...
> > End If
> > ///
> >



 
Reply With Quote
 
aussie rules
Guest
Posts: n/a
 
      22nd May 2004
Hi all,

Thanks for the feedback.

I failed to mention that the text boxs may have been pre-populated when the
form loaded with current data. The length of therefore of a textbox will be
> 1.


any other ideas

"Cor Ligthert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Ray,
>
> No an example how to do simple things in a difficult way.
>
> Cor
>
> > > \\\
> > > Private m_Dirty As Boolean
> > > .
> > > .
> > > .
> > > Public Sub TextBox_TextChanged( _
> > > ByVal sender As Object, _
> > > ... _
> > > ) _
> > > Handles Me.TextBox1.TextChanged, Me.TextBox2.TextChanged, ...
> > > If DirectCast(sender, TextBox).TextLength > 0 Then
> > > m_Dirty = True
> > > End If
> > > End Sub
> > > .
> > > .
> > > .
> > > If m_Dirty Then
> > > ...
> > > Else
> > > ...
> > > End If
> > > ///
> > >

>
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      23rd May 2004
* "Cor Ligthert" <(E-Mail Removed)> scripsit:
> No an example how to do simple things in a difficult way.


What's difficult?!

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      23rd May 2004
* "aussie rules" <(E-Mail Removed)> scripsit:
> I failed to mention that the text boxs may have been pre-populated when the
> form loaded with current data. The length of therefore of a textbox will be
>> 1.


You could store the standard text of each textbox in its 'Tag' property
too and then compare its content to the value of this property in order
to find out if the control is "dirty".

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
Ray Cassick \(Home\)
Guest
Posts: n/a
 
      23rd May 2004
I am kind of curious about what he felt was more difficult about writing an
extender control as well.

Write the code once that attaches to all controls on a form and allows you
to check with one property if there was any changes made to any of the
controls on that form.

Very easy task? No, but you do all the hard work up front once and reap the
rewards of code reuse for all your latter projects.

"Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
news:esl$(E-Mail Removed)...
> * "Cor Ligthert" <(E-Mail Removed)> scripsit:
> > No an example how to do simple things in a difficult way.

>
> What's difficult?!
>
> --
> Herfried K. Wagner [MVP]
> <URL:http://dotnet.mvps.org/>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      23rd May 2004
>
> What's difficult?!


See my first answer, in code that is a simple routine as this bellow for all
textboxes, and than you start telling to use the handlers as a reply on
that.

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
For Each ctr As Control In Me.Controls
If TypeOf ctr Is TextBox Then
ctr.Tag = ctr.Text
End If
Next
End Sub

Private Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button1.Click
For Each ctr As Control In Me.Controls
If TypeOf ctr Is TextBox Then
If ctr.Tag.ToString <> ctr.Text Then
MessageBox.Show("do you want to save the items")
End If
End If
Next
End Sub
///


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unbound form, "dirty" textbox identify in code Hindsey Microsoft Access 1 12th Mar 2009 06:34 PM
How change "Flag Status" from "Red Flag" to "Urgent"? =?Utf-8?B?Um9zY29l?= Microsoft Outlook Discussion 0 29th Sep 2006 03:00 PM
Manually clear the "DIRTY" Flag? Chkdsk runs every time I boot in =?Utf-8?B?TXIgQg==?= Windows XP General 3 2nd Nov 2005 05:23 PM
How to change "Red Flag" "Green Flag" ... in Outlook 2003 =?Utf-8?B?TG91aXMgSmltZW5leg==?= Microsoft Outlook Discussion 3 29th Jan 2004 10:46 AM
Check if custom form is "dirty" or form data has changed ? =?Utf-8?B?QWRhbSBHcmFuZ2Vy?= Microsoft Outlook VBA Programming 3 14th Nov 2003 11:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:28 PM.