Click here to Skip to main content
16,008,469 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: dim f as string Pin
Christian Graus5-Jul-07 1:13
protectorChristian Graus5-Jul-07 1:13 
QuestionNumerical textbox validation, how to handle an empty string? [modified] Pin
MatthysDT5-Jul-07 0:09
MatthysDT5-Jul-07 0:09 
AnswerRe: Numerical textbox validation, how to handle an empty string? Pin
SHatchard5-Jul-07 0:19
SHatchard5-Jul-07 0:19 
QuestionRe: Numerical textbox validation, how to handle an empty string? Pin
MatthysDT5-Jul-07 1:25
MatthysDT5-Jul-07 1:25 
NewsRe: Numerical textbox validation, how to handle an empty string? Pin
MatthysDT5-Jul-07 1:55
MatthysDT5-Jul-07 1:55 
AnswerRe: Numerical textbox validation, how to handle an empty string? Pin
cutequencher5-Jul-07 6:05
cutequencher5-Jul-07 6:05 
GeneralRe: Numerical textbox validation, how to handle an empty string? Pin
MatthysDT6-Jul-07 0:51
MatthysDT6-Jul-07 0:51 
AnswerAnswer.... Pin
MatthysDT16-Jul-07 2:36
MatthysDT16-Jul-07 2:36 
O.k, I found a work-around for the problem. Posting it here for the sake of anyone having similar problems.

What happens that causes the problem is that VS doesn't allow a control (in my case a textbox) to lose focus if the text inside it doesn't validate. But for numerical textboxes it also doesn't validate empty strings, even if you want the user to be able to add an empty string.

The solution is to set the data source update mode to never, this disables .Net validation on the control, allowing you to do this with custom code.
Me.MyNumericTextBox.DataBindings.DefaultDataSourceUpdateMode = DataSourceUpdateMode.Never


The validating event still fires though, but it's under YOUR control now, so the following code will allow you to force the user to enter either a numerical value, or an EMPTY STRING.
    Private Sub MyNumericTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyNumericTextBox.Validating
        If String.IsNullOrEmpty(Me.MyNumericTextBox.Text) OrElse IsNumeric(Me.MyNumericTextBox.Text) Then
            MyErrorProvider.SetError(Me.MyNumericTextBox, "") 'Fire or cancel the 
'error in whatever way suites you, this simply clears the errorprovider
        Else
            MyErrorProvider.SetError(Me.MyNumericTextBox, "The value must be numeric") 'Fire or
'cancel the error in whatever way suites you, this sets the error on the errorprovider

            Me.MyNumericTextBox.Focus() 'This forces the user to enter the validated 
'data before leaving the control
        End If
    End Sub


Please reply to this post for more information.


_______________________________________________________________________
http://www.readytogiveup.com/[^]
"you can't forget something you never knew..." M. Du Toit



AnswerRe: word document Pin
Christian Graus4-Jul-07 23:47
protectorChristian Graus4-Jul-07 23:47 
QuestionImage Icon in setup program Pin
ShuklaGirish4-Jul-07 23:06
ShuklaGirish4-Jul-07 23:06 
AnswerRe: Image Icon in setup program Pin
kubben5-Jul-07 2:46
kubben5-Jul-07 2:46 
AnswerRe: Image Icon in setup program Pin
pashitech5-Jul-07 5:47
pashitech5-Jul-07 5:47 
GeneralRe: Image Icon in setup program Pin
ShuklaGirish5-Jul-07 18:52
ShuklaGirish5-Jul-07 18:52 
QuestionHow to pass value of a variable of one form to the next in vb.net Pin
Projrct_Friend's4-Jul-07 21:56
Projrct_Friend's4-Jul-07 21:56 
AnswerRe: How to pass value of a variable of one form to the next in vb.net Pin
Johan Hakkesteegt4-Jul-07 22:14
Johan Hakkesteegt4-Jul-07 22:14 
GeneralRe: How to pass value of a variable of one form to the next in vb.net Pin
Christian Graus5-Jul-07 1:11
protectorChristian Graus5-Jul-07 1:11 
AnswerRe: How to pass value of a variable of one form to the next in vb.net Pin
Mycroft Holmes4-Jul-07 23:01
professionalMycroft Holmes4-Jul-07 23:01 
GeneralRe: How to pass value of a variable of one form to the next in vb.net Pin
Johan Hakkesteegt4-Jul-07 23:21
Johan Hakkesteegt4-Jul-07 23:21 
AnswerRe: How to pass value of a variable of one form to the next in vb.net Pin
Christian Graus5-Jul-07 1:12
protectorChristian Graus5-Jul-07 1:12 
Questionthis code was working in form1 and did not work in form2 Pin
magedhv4-Jul-07 21:44
magedhv4-Jul-07 21:44 
AnswerRe: this code was working in form1 and did not work in form2 Pin
magedhv4-Jul-07 21:48
magedhv4-Jul-07 21:48 
GeneralRe: this code was working in form1 and did not work in form2 Pin
SHatchard4-Jul-07 21:56
SHatchard4-Jul-07 21:56 
GeneralRe: this code was working in form1 and did not work in form2 Pin
magedhv4-Jul-07 22:07
magedhv4-Jul-07 22:07 
GeneralRe: this code was working in form1 and did not work in form2 Pin
magedhv4-Jul-07 22:11
magedhv4-Jul-07 22:11 
GeneralRe: this code was working in form1 and did not work in form2 Pin
SHatchard4-Jul-07 23:03
SHatchard4-Jul-07 23:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.