Click here to Skip to main content
16,005,080 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: thanks Pin
TwoFaced15-Mar-07 12:59
TwoFaced15-Mar-07 12:59 
Generalperfect... Pin
manni_n15-Mar-07 13:12
manni_n15-Mar-07 13:12 
Generalcheck it... Pin
manni_n15-Mar-07 13:23
manni_n15-Mar-07 13:23 
GeneralRe: check it... [modified] Pin
TwoFaced15-Mar-07 14:07
TwoFaced15-Mar-07 14:07 
GeneralRe: check it... Pin
manni_n16-Mar-07 1:05
manni_n16-Mar-07 1:05 
GeneralRe: check it... Pin
TwoFaced16-Mar-07 6:30
TwoFaced16-Mar-07 6:30 
GeneralRe: check it... Pin
manni_n16-Mar-07 8:34
manni_n16-Mar-07 8:34 
GeneralRe: check it... Pin
TwoFaced16-Mar-07 10:13
TwoFaced16-Mar-07 10:13 
Okay I see the mistake. Well I assume it's a mistake. Maybe you reverted back to using the TextChanged event because you couldn't get it to work, but I'll assume for the moment you didn't. When you use AddHandler you never changed the event that would be handled.

The following line
AddHandler ctrl.TextChanged, AddressOf txtvalidate_validating

Should be:
AddHandler ctrl.Validating, AddressOf txtvalidate_validating

The portion after Addhandler is the event that gets handled. The portion after addressof is the method that does the handling. In this case we want to handle the validating event which is the change I made above.

e.cancel = true should occur when validation fails. Also you changed the parameters for the txtValidate_Validating procedure. Probably because you were getting errors do to the fact that the event you were trying to handle was the TextChanged event and not the validating event.

The final code should be this:

Public Class Form1<br />
    Inherits System.Windows.Forms.Form<br />
    Private TextBoxCollection As New ArrayList<br />
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
        For Each ctrl As Control In Me.Controls<br />
            If TypeOf ctrl Is TextBox Then<br />
                TextBoxCollection.Add(DirectCast(ctrl, TextBox))<br />
                AddHandler ctrl.Validating, AddressOf txtvalidate_validating<br />
            End If<br />
        Next<br />
    End Sub<br />
<br />
    Private Sub txtvalidate_validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)<br />
        Dim txtSender As TextBox = DirectCast(sender, TextBox)<br />
        For Each txt As TextBox In TextBoxCollection<br />
            If Not txt Is txtSender AndAlso txt.Text = txtSender.Text AndAlso txt.Text <> "" Then<br />
                MsgBox("You have already filled this value")<br />
                e.Cancel = True<br />
                Exit For<br />
            End If<br />
        Next<br />
    End Sub<br />
End Class


If there is a problem with this code it's because of differences in 2003 vs 2005. But this code works perfectly under 2005.
Generalcool... [modified] Pin
manni_n16-Mar-07 11:06
manni_n16-Mar-07 11:06 
GeneralRe: cool... Pin
TwoFaced16-Mar-07 12:11
TwoFaced16-Mar-07 12:11 
QuestionChecked List Box Pin
taherjaorawala14-Mar-07 21:46
taherjaorawala14-Mar-07 21:46 
AnswerRe: Checked List Box Pin
manni_n14-Mar-07 23:13
manni_n14-Mar-07 23:13 
QuestionTyped dataset, insert, return output parameter Pin
steve_rm14-Mar-07 19:38
steve_rm14-Mar-07 19:38 
AnswerRe: Typed dataset, insert, return output parameter Pin
Steven J Jowett15-Mar-07 1:57
Steven J Jowett15-Mar-07 1:57 
QuestionTotal Hours and minutes Pin
Member 387988114-Mar-07 19:03
Member 387988114-Mar-07 19:03 
AnswerRe: Total Hours and minutes Pin
Tirthadip14-Mar-07 23:39
Tirthadip14-Mar-07 23:39 
GeneralRe: Total Hours and minutes Pin
Member 387988114-Mar-07 23:56
Member 387988114-Mar-07 23:56 
GeneralRe: Total Hours and minutes Pin
coolestCoder15-Mar-07 2:25
coolestCoder15-Mar-07 2:25 
GeneralRe: Total Hours and minutes Pin
Member 387988115-Mar-07 0:17
Member 387988115-Mar-07 0:17 
QuestionMaking User Under WinXP/NT/2000 (NT Family) With VB or API Pin
Mogtabam14-Mar-07 18:34
Mogtabam14-Mar-07 18:34 
Questionlittle problem with codes :) Pin
alpdoruk14-Mar-07 13:28
alpdoruk14-Mar-07 13:28 
AnswerRe: little problem with codes :) Pin
JUNEYT14-Mar-07 13:35
JUNEYT14-Mar-07 13:35 
AnswerRe: little problem with codes :) Pin
alpdoruk14-Mar-07 13:44
alpdoruk14-Mar-07 13:44 
Answersolved now Pin
alpdoruk14-Mar-07 13:47
alpdoruk14-Mar-07 13:47 
GeneralRe: little problem with codes :) Pin
JUNEYT14-Mar-07 13:50
JUNEYT14-Mar-07 13:50 

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.