Problem adding code for dynamically created text boxes
Problem adding code for dynamically created text boxes
Problem adding code for dynamically created text boxes
Problem adding code for dynamically created text boxes
Problem adding code for dynamically created text boxes
Problem adding code for dynamically created text boxes Problem adding code for dynamically created text boxes Problem adding code for dynamically created text boxes Problem adding code for dynamically created text boxes Problem adding code for dynamically created text boxes Problem adding code for dynamically created text boxes Problem adding code for dynamically created text boxes Problem adding code for dynamically created text boxes
Problem adding code for dynamically created text boxes Problem adding code for dynamically created text boxes
Problem adding code for dynamically created text boxes
Go Back  Xtreme Visual Basic Talk > > > Problem adding code for dynamically created text boxes


Reply
 
Thread Tools Display Modes
  #1  
Old 03-01-2014, 06:38 AM
kjcorbel kjcorbel is offline
Newcomer
 
Join Date: May 2009
Posts: 13
Default Problem adding code for dynamically created text boxes


In my project I have many dynamically created controls, for which I am writing code for. I have not had any problem with these with the exception of the TextBoxes. I would like to have a Return keypress force focus onto the next control. (Yes I know it would have to be the keydown event) But the AddHandler line gives the message "Nested sub does not have a signature that is compatible with delegate "Delegate Sub KeyEventHandler(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)"

The problematic Addhandler line is for the KeyDown event.
Code:
            For X = 0 To indexNum
                Dim tempField As New TextBox
                AddHandler tempField.GotFocus, New EventHandler(AddressOf txtField_GotFocus)
                AddHandler tempField.LostFocus, New EventHandler(AddressOf txtField_LostFocus)
                AddHandler tempField.KeyDown, New EventHandler(AddressOf txtField_KeyDown)
                With tempField
                    .Font = txtFieldModel.Font
                    .Top = txtFieldModel.Top + Int(txtFieldModel.Height * Int(X / 5) * 1.5)
                    .Left = txtFieldModel.Left + (txtFieldModel.Width + 15) * (X Mod 5)
                    .Width = txtFieldModel.Width
                    .Text = fieldText(X)
                End With
                Controls.Add(tempField)
                txtField(X) = tempField
            Next
And the Sub
Code:
   Private Sub txtField_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        Dim i As Integer

        i = Array.IndexOf(txtField, sender)
        If e.KeyCode = Keys.Return Then
            If i < cmbNumFields.SelectedIndex Then
                txtField(i + 1).Focus()
            Else
                chkBoys(0).Focus()
            End If
            e.Handled = True
            e.SuppressKeyPress = True
        End If
    End Sub
What am I missing or doing wrong?
Thank you.
Reply With Quote
  #2  
Old 03-01-2014, 10:53 AM
snarfblam's Avatar
snarfblamProblem adding code for dynamically created text boxes snarfblam is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Apr 2005
Location: USA
Posts: 896
Default

The error message is misleading. Just change
Code:
AddHandler tempField.KeyDown, New EventHandler(AddressOf txtField_KeyDown)
to
Code:
AddHandler tempField.KeyDown, New KeyEventHandler(AddressOf txtField_KeyDown)
or even
Code:
AddHandler tempField.KeyDown, AddressOf txtField_KeyDown
__________________
C# _VB.NET _
Reply With Quote
  #3  
Old 03-01-2014, 11:16 AM
passel's Avatar
passelProblem adding code for dynamically created text boxes passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Do you need to create a New handler for each textbox MouseDown?
It seems like the code might work using the same handler for all the textboxes.

AddHandler tempField.KeyDown, AddressOf txtField_KeyDown

edit: Nevermind, took me too long to investigate, snarfblam has you covered.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #4  
Old 03-02-2014, 01:04 AM
kjcorbel kjcorbel is offline
Newcomer
 
Join Date: May 2009
Posts: 13
Default

Thank you, that is exactly what I needed.
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
Problem adding code for dynamically created text boxes
Problem adding code for dynamically created text boxes
Problem adding code for dynamically created text boxes Problem adding code for dynamically created text boxes
Problem adding code for dynamically created text boxes
Problem adding code for dynamically created text boxes
Problem adding code for dynamically created text boxes Problem adding code for dynamically created text boxes Problem adding code for dynamically created text boxes Problem adding code for dynamically created text boxes Problem adding code for dynamically created text boxes Problem adding code for dynamically created text boxes Problem adding code for dynamically created text boxes
Problem adding code for dynamically created text boxes
Problem adding code for dynamically created text boxes
 
Problem adding code for dynamically created text boxes
Problem adding code for dynamically created text boxes
 
-->