|
-
Oct 25th, 2003, 02:46 PM
#1
Thread Starter
Frenzied Member
enable button
I have a save button on a form with 20 textboxes. I have it set to enable = false till I detect some changes in the textboxes and then change it to enable = true...whats the most efficient way to do besides checking the change event for each textbox?
thanks
It's tough being an unhandled exception...
___________
VB.NET 2008
VB.NET 2010
ORACLE 11g
CRYSTAL 11
-
Oct 25th, 2003, 03:55 PM
#2
Addicted Member
the way i would do it is to add a sub that handles the validated event of all the text boxes, and there enable and disable your save button
( and i would add a sub that handles all the validating event of the text boxes , and cancel bad data input there )
-
Oct 25th, 2003, 08:47 PM
#3
Addicted Member
If you mean that a change in any of the the textboxes can activate the button, you could use something like this:
VB Code:
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
If ctrl.Text <> Nothing Then
SaveButton.Enable = True
End If
End If
Next
Take my love
Take my land
Take me where I cannot stand
I don't care, I'm still free
You can't take the sky from me...
-
Oct 26th, 2003, 12:22 PM
#4
Thread Starter
Frenzied Member
does that code in the text change event? place it in there and did not flag any activity for the textbox?
It's tough being an unhandled exception...
___________
VB.NET 2008
VB.NET 2010
ORACLE 11g
CRYSTAL 11
-
Oct 26th, 2003, 02:04 PM
#5
you need to add a handler for all textboxes ( maybe on form load ) eg:
VB Code:
[Color=Blue]Private[/COLOR] [Color=Blue]WithEvents[/COLOR] txtBox [Color=Blue]As[/COLOR] TextBox
[Color=Blue]Private[/COLOR] [Color=Blue]Sub[/COLOR] Form1_Load([Color=Blue]ByVal[/COLOR] sender [Color=Blue]As[/COLOR] System.Object, [Color=Blue]ByVal[/COLOR] e [Color=Blue]As[/COLOR] System.EventArgs) [Color=Blue]Handles[/COLOR] [Color=blue]MyBase[/color].Load
[Color=Blue]Dim[/COLOR] tb [Color=Blue]As[/COLOR] Control
[Color=Blue]For[/COLOR] [Color=Blue]Each[/COLOR] tb [Color=Blue]In[/COLOR] Controls
[Color=Blue]If[/COLOR] [Color=Blue]TypeOf[/COLOR] tb [Color=Blue]Is[/COLOR] TextBox [Color=Blue]Then
[/COLOR] [Color=Blue]AddHandler[/COLOR] tb.TextChanged, [Color=Blue]AddressOf[/COLOR] txtBox_TextChanged
[Color=Blue]End[/COLOR] [Color=Blue]If[/COLOR]
[Color=Blue]Next
[/COLOR] [Color=Blue]End[/COLOR] [Color=Blue]Sub
[/COLOR] [Color=Blue]Private[/COLOR] [Color=Blue]Sub[/COLOR] txtBox_TextChanged([Color=Blue]ByVal[/COLOR] sender [Color=Blue]As[/COLOR] [Color=Blue]Object[/COLOR], [Color=Blue]ByVal[/COLOR] e [Color=Blue]As[/COLOR] System.EventArgs) [Color=Blue]Handles[/COLOR] txtBox.TextChanged
[Color=Green]'///[/COLOR] [Color=Green]all[/COLOR] [Color=Green]textboxes[/COLOR] [Color=Green]on[/COLOR] [Color=Green]this[/COLOR] [Color=Green]form[/COLOR] [Color=Green]now[/COLOR] [Color=Green]have[/COLOR] [Color=Green]the[/COLOR] [Color=Green]TextChanged[/COLOR] [Color=Green]event[/COLOR] [Color=Green]handled[/COLOR] [Color=Green]here.
[/COLOR] [Color=Blue]End[/COLOR] [Color=Blue]Sub[/COLOR]
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Oct 26th, 2003, 03:12 PM
#6
Thread Starter
Frenzied Member
do I need to name each textbox here?
VB Code:
AddressOf txtBox_TextChanged
where do I set the btnSave.enabled = true?
in each txtbox change event? doesn't that defeat the purpose of creating a handler?
It's tough being an unhandled exception...
___________
VB.NET 2008
VB.NET 2010
ORACLE 11g
CRYSTAL 11
-
Oct 26th, 2003, 03:17 PM
#7
Addicted Member
Code:
For Each tb In Controls
If TypeOf tb Is TextBox Then
AddHandler tb.TextChanged, AddressOf (any event handler )
End If
Next
no you dont need the name, when using the code above (as dynamic... wrote )
-
Oct 26th, 2003, 03:24 PM
#8
Thread Starter
Frenzied Member
in which event would the code go into?
It's tough being an unhandled exception...
___________
VB.NET 2008
VB.NET 2010
ORACLE 11g
CRYSTAL 11
-
Oct 26th, 2003, 03:26 PM
#9
Addicted Member
sorry didnt see the all your questions
where do I set the btnSave.enabled = true ?
in the event handler
in case your using dynamic_sysop sample it would look like this
Code:
Private Sub txtBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBox.TextChanged
btnSave.Enabled=True
End Sub
in each txtbox change event? doesn't that defeat the purpose of creating a handler?
didnt really understand what your asking, but here you just have 1 handler for all the text boxes
-
Oct 26th, 2003, 03:36 PM
#10
Thread Starter
Frenzied Member
I meant I have 20 textboxes on my screen , so I would have to name each handler (textbox) here?
VB Code:
AddressOf txtBox_TextChanged
It's tough being an unhandled exception...
___________
VB.NET 2008
VB.NET 2010
ORACLE 11g
CRYSTAL 11
-
Oct 26th, 2003, 03:39 PM
#11
Addicted Member
this is all you need, you dont have to add or remove anything ( you dont need the textbox names )
Code:
Private WithEvents txtBox As TextBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim tb As Control
For Each tb In Controls
If TypeOf tb Is TextBox Then
AddHandler tb.TextChanged, AddressOf txtBox_TextChanged
End If
Next
End Sub
Private Sub txtBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBox.TextChanged
BtnSave.Enabled=True
End Sub
-
Oct 26th, 2003, 04:00 PM
#12
Thread Starter
Frenzied Member
still not woeking...I have my textboxes in a groupbox...could this be why it's not being read as a control?
It's tough being an unhandled exception...
___________
VB.NET 2008
VB.NET 2010
ORACLE 11g
CRYSTAL 11
-
Oct 26th, 2003, 04:06 PM
#13
Addicted Member
try this,
Code:
For Each txt In GroupBox1.Controls
istead of
Code:
For Each tb In Controls
-
Oct 26th, 2003, 04:11 PM
#14
Thread Starter
Frenzied Member
thanks persian, that did it...
It's tough being an unhandled exception...
___________
VB.NET 2008
VB.NET 2010
ORACLE 11g
CRYSTAL 11
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|