Save Button class?
Save Button class?
Save Button class?
Save Button class?
Save Button class?
Save Button class? Save Button class? Save Button class? Save Button class? Save Button class? Save Button class? Save Button class? Save Button class?
Save Button class? Save Button class?
Save Button class?
Go Back  Xtreme Visual Basic Talk > > > Save Button class?


Reply
 
Thread Tools Display Modes
  #1  
Old 07-25-2013, 01:48 PM
RM33 RM33 is offline
Newcomer
 
Join Date: Jan 2013
Posts: 20
Default Save Button class?


I put the following code into a save button. Basically, all the textboxes have a property that is set to false when the data in it is not valid. And the validation occurs when the user leaves the textbox. For example, if a user enters a social security number in the wrong format, and tries to move off, it triggers a validation error. Here is the code in the save button.

Dim ctrl As Control = Me.GetNextControl(Me, True) 'Get the first control in the tab order.

Do Until ctrl Is Nothing 'Use ctrl here.

If (TypeOf ctrl Is clsTextBox) Then
Dim mtb As clsTextBox = CType(ctrl, clsTextBox)

mtb.Focus()
SendKeys.SendWait("{TAB}")

If Not mtb.IsValidated Then
mtb.Focus()
Exit Do
End If

End If

ctrl = Me.GetNextControl(ctrl, True) 'Get the next control in the tab order.
Loop

The above code works in a save button.

I tried to put the above code in a save button class so when the programmer drags and drops the save button onto a form, by default, the above code will run. The problem is that the same code above in a class is not aware of the form it is on. The command Me. only recognizes the button, and not the form the button is on. How do you make the save button class recognize the form it is on?

Below is what I got so far for my save button class.


Private Sub Button_Click(sender As System.Object, e As System.EventArgs) Handles MyBase.Click


If UCase(CType(sender, Control).Name) = "CMDSAVE" Then

Dim ctrl As Control = Me.GetNextControl(Me, True) 'Get the first control in the tab order.

Do Until ctrl Is Nothing 'Use ctrl here.

If (TypeOf ctrl Is clsTextBox) Then
Dim mtb As clsTextBox = CType(ctrl, clsTextBox)

mtb.Focus()
SendKeys.SendWait("{TAB}")

If Not mtb.IsValidated Then
mtb.Focus()
Exit Do
End If

End If

ctrl = Me.GetNextControl(ctrl, True) 'Get the next control in the tab order.
Loop

End If


End Sub
Reply With Quote
  #2  
Old 07-25-2013, 02:55 PM
Gruff's Avatar
GruffSave Button class? Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Is there a question in there some where?

P.S. Not sure why you posted this in the graphics forum area.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #3  
Old 07-26-2013, 02:40 AM
DrPunk's Avatar
DrPunkSave Button class? DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

I think the question is how to find the parentform of a button control.

Control's have a Parent property, but put a control in a panel and the panel is the Parent, not the form so you can't rely on it to give you the form the control is on.

This does seem like a bit of a waste of time. The whole Validation thing is already taken care of with a control's Validating event. If Validation fails the user can not leave the control. If you use that then the validation done by this button would never occur, cos you cannot click it if the textbox is not Validated. All the save button would do in that case is run validation that has already been validated.
__________________
There are no computers in heaven!
Reply With Quote
  #4  
Old 07-26-2013, 11:16 AM
Gruff's Avatar
GruffSave Button class? Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

I validate that answer!
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #5  
Old 07-30-2013, 08:46 AM
RM33 RM33 is offline
Newcomer
 
Join Date: Jan 2013
Posts: 20
Default

Quote:
Originally Posted by DrPunk View Post
I think the question is how to find the parentform of a button control.

Control's have a Parent property, but put a control in a panel and the panel is the Parent, not the form so you can't rely on it to give you the form the control is on.

This does seem like a bit of a waste of time. The whole Validation thing is already taken care of with a control's Validating event. If Validation fails the user can not leave the control. If you use that then the validation done by this button would never occur, cos you cannot click it if the textbox is not Validated. All the save button would do in that case is run validation that has already been validated.
Sorry. My apologies Dr. Punk. I did the post quickly before I went home and confused 2 ideas. Yes validation does not require a second check.

I believe that management does not like the idea of validation. So I need options.

I wanted to put the code below into a save custom control. I am sure that they would like that idea. The problem is that how do I get a command button custom control to recognize the form that the save button custom control sits on? Is it possible to have the code below in a button custom class. If so it would be good because the company will have a "universal save checking" as a default behavior.

Like I said above, there is checking done when the user moves off the textbox so the code below goes to each textbox and move thus triggering the checking.

Code:


Dim ctrl As Control = Me.GetNextControl(Me, True) 'Get the first control in the tab order.

Do Until ctrl Is Nothing 'Use ctrl here.

If (TypeOf ctrl Is clsTextBox) Then
Dim mtb As clsTextBox = CType(ctrl, clsTextBox)

mtb.Focus()
SendKeys.SendWait("{TAB}")

If Not mtb.IsValidated Then
mtb.Focus()
Exit Do
End If

End If

ctrl = Me.GetNextControl(ctrl, True) 'Get the next control in the tab order.
Loop
Reply With Quote
  #6  
Old 07-30-2013, 08:53 AM
DrPunk's Avatar
DrPunkSave Button class? DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

Quote:
Originally Posted by RM33 View Post
The problem is that how do I get a command button custom control to recognize the form that the save button custom control sits on?
So why not create a SaveForm custom Form Control?

You could have a SaveButton property that when set to a button adds a handler to its click event and then runs what you would have put in the button click event.

Dunno. Just a different idea.
__________________
There are no computers in heaven!
Reply With Quote
  #7  
Old 07-30-2013, 09:13 AM
DrPunk's Avatar
DrPunkSave Button class? DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

Quote:
Originally Posted by DrPunk View Post
You could have a SaveButton property that when set to a button adds a handler to its click event and then runs what you would have put in the button click event.
I say you could, but I maybe should've checked first. Doesn't seem that easy. Not sure how to make an AcceptButton style property for a control.

I also didn't consider that inherited forms are a bit different to inherited controls.
__________________
There are no computers in heaven!
Reply With Quote
  #8  
Old 07-30-2013, 09:23 AM
DrPunk's Avatar
DrPunkSave Button class? DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

The answer to the question of the thread is the Button's FindForm method.

http://msdn.microsoft.com/en-us/libr....findform.aspx
__________________
There are no computers in heaven!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Save Button class?
Save Button class?
Save Button class? Save Button class?
Save Button class?
Save Button class?
Save Button class? Save Button class? Save Button class? Save Button class? Save Button class? Save Button class? Save Button class?
Save Button class?
Save Button class?
 
Save Button class?
Save Button class?
 
-->