Solved

How do I disable the textchanged event of a textbox once it has been fired?

Posted on 2006-11-21
6
2,277 Views
Last Modified: 2008-02-01
I have VS2005. I have on a form a textbox(TextBox1) and a datagrid.  A barcode is entered into TextBox1 with a barcode scanner which fires the textchanged event and loads data from the database into the datagrid that coresponds to the barcode entered. I'm trying to set this up so I can enter more than one barcode to bring up more data for each barcode. I found using the textchanged event that when I clear just one number from the barcode in TextBox1 that the entry in the datagird clears. The textchanged event still fires clearing the entry from the datagrid. I would like to clear TextBox1 without clearing the entry in the datagrid. Is there a way to disable the textchanged event and then re-enable it when a new row is added to the datagrid?

Thanks
0
Comment
Question by:grouchyfd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 17

Accepted Solution

by:
ZeonFlash earned 500 total points
ID: 17990597
You can add/remove the event handler like this:

RemoveHandler TextBox1_TextChanged, AddressOf TextBox1.TextChanged
AddHandler TextBox1_TextChanged, AddressOf TextBox1.TextChanged
0
 
LVL 7

Expert Comment

by:davidrichardson
ID: 17990702
An alternative to using text change event, my scanner simulates an enter keypress when scanned so this is what I use

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean


        If msg.WParam.ToInt32() = CInt(Keys.Enter) Then
            If Len(txtscan.Text) = 9 Then
                Me.DialogResult = System.Windows.Forms.DialogResult.OK
                Return True
            Else
                MsgBox("Please Enter A Valid Sales Order")
            End If
        End If

        Return MyBase.ProcessCmdKey(msg, keyData)
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 17990725
You can just set a flag to ignore the event:

Public Class Form1

    Private ClearFlag As Boolean = False

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        If Not ClearFlag Then
            Debug.Print("TextChanged()")

        End If
    End Sub

    Private Sub ClearTextBox()
        ClearFlag = True
        TextBox1.Clear()
        ClearFlag = False
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ClearTextBox()
    End Sub

End Class
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:grouchyfd
ID: 17990798
Here is the sub to enter the data from the database that coresponds to the barcode:

Private Sub txtBarcode_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBarcode.TextChanged
        StockStatusTableAdapter.FillByBarcode(VStockStatus.StockStatus, txtBarcode.Text)

    End Sub
When I added the RemoveHandler event by itself, the datagrid would not load. When I add the AddHandler then the datagrid loads but then as soon as you backspace one digit of the barcode, it still clears out the data from the datagrid(the same as wihtout the RemoveHandler and AddHandler). What am I doing wrong here?
0
 
LVL 15

Expert Comment

by:Solar_Flare
ID: 17992006
is this what you tried?

Private Sub txtBarcode_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBarcode.TextChanged
        StockStatusTableAdapter.FillByBarcode(VStockStatus.StockStatus, txtBarcode.Text)
        removehandler txtBarcode.TextChanged, addressof txtBarcode_TextChanged
    End Sub
0
 

Author Comment

by:grouchyfd
ID: 18012028
I appologize for the long delay. Yes, that is what I tried.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question