By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,956 Members | 1,683 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,956 IT Pros & Developers. It's quick & easy.

How do I make this work, Private Sub TextBox1_TextChanged(ByVal sender As System.Obje

P: 1
How do I make this work for VB- Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NameBox.TextChanged
Mar 8 '14 #1
Share this Question
Share on Google+
4 Replies


100+
P: 294
Well, what do you mean 'work' ? What's wrong with it? It's a method that is being called when the Text is changed inside TextBox1.
Mar 11 '14 #2

P: 12
this method will triggered in when you type or anything you want to do with your textbox..ontextchange then ?????? for example:
you type this code in your OnTextChanged.....
text1.text="sample"
when you pressed any key on the keyboard it will show a "sample" always...
Hope this will help you out....
Mar 12 '14 #3

SebastYin
P: 1
Very vague question, but I will give you an example of how it would work.

Expand|Select|Wrap|Line Numbers
  1. 'Button Changes Textbox1's Text.
  2.   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  3.         TextBox1.Text = "New Text"
  4.     End Sub
  5. 'Messagebox displayed to show Textbox1's Text.
  6.     Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
  7.         MsgBox("Text of TextBox1 has changed to: " & TextBox1.Text)
  8.  
  9. End Sub
  10.  
Mar 15 '14 #4

Frinavale
Expert Mod 5K+
P: 9,731
If the TextBox is dynamically added, you need to declare it with events and use the AddHandler method to link the TextChanged event to the method that handles it.

For example (The following code is NOT tested and is only meant as a guideline because I don't know what type of project you are working with):
Expand|Select|Wrap|Line Numbers
  1. Private WithEvents TextBox1 As TextBox
  2.  
  3. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4.        If Not Me.Controls.Contains(TextBox1) Then
  5.           AddHandler TextBox1.TextChanged, AddressOf TextBox1_TextChanged
  6.           Me.Controls.Add(TextBox1)
  7.        End If
  8. End Sub
  9. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  10.         TextBox1.Text = "New Text"
  11. End Sub
  12.  
  13. Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) 
  14.         MsgBox("Text of TextBox1 has changed to: " & TextBox1.Text)
  15. End Sub
  16.  
  17.  
-Frinny
Mar 18 '14 #5

Post your reply

Sign in to post your reply or Sign up for a free account.