错误提供者-文本框不能为空 [英] error provider- textbox can't be blank

查看:106
本文介绍了错误提供者-文本框不能为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文本框不能为空,并且有12个文本框,甚至没有一个文本框都可以为空,因此如何显示错误消息并在该文本框上显示光标焦点.

我写的..

textbox can''t be blank and there are 12 textbox and not even a single textbox can be blank so how can i show error message and show focus of cursor on that textbox.

i wrote that..

Dim ctl As Control
        For Each ctl In Me.Controls
            If TypeOf (ctl) Is TextBox Then
                If ctl.Text = "" Then

                    MsgBox("Please Enter the text ", MsgBoxStyle.Information, "Note")
                Else
                    ctl.Focus()
                End If
            End If
        Next




但这不起作用...所以请帮我plz




but this is not working...so help me plz

推荐答案

尝试一下

try this

Dim ctl As Control
 For Each ctl In Me.Controls
 If TypeOf (ctl) Is TextBox Then
 If ctl.Text.Length = 0 Then

 MsgBox("Please Enter the text ", MsgBoxStyle.Information, "Note")
 Else
 ctl.Focus()
 End If
 End If
 Next


如何操作:
How about this:
Dim ctl As Control
For Each ctl In Me.Controls
    If TypeOf (ctl) Is TextBox Then
        'In this next line, I added a .Trim to get rid of spaces and used theanil's method of using the .Length and comparing it to zero instead of checking for an empty string.
        If ctl.Text.Trim.Length = 0 Then
            MsgBox("Please Enter the text ", MsgBoxStyle.Information, "Note")
            'I removed the else because I figured you wanted to set focus when the box was empty
            ctl.Focus()
            'I added the Exit For because once you've found an empty box you want to stop your checking
            Exit For
        End If
    End If
Next


这篇关于错误提供者-文本框不能为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆