Solved

VB 2005 Combobox TextChanged Event.  Distinguish between programmatic modification or user interaction.

Posted on 2008-10-29
2
726 Views
Last Modified: 2012-05-05
I'm populating a combobox in vb 2005 like this.  This line in the code is calling the TextChanged event.
cmbfiletypecode.Text = dr("filetypecode").ToString.Trim

When a user changes one of the values in the combo box it calls the same event.  How can I isolate whether the user has changed a value or it's been changed programatically?



        dt4.Clear()
        cCmd.CommandText = "Select distinct FileTypecode from FileType where FileTypecode is not null order by FileTypecode"
        adapter.SelectCommand = cCmd
        adapter.Fill(dt4)
        cmbFileTypeCode.DisplayMember = "FileTypecode"
        cmbFileTypeCode.ValueMember = "FileTypecode"
        cmbFileTypeCode.DataSource = dt4
        dt4a.Clear()
        cCmd.CommandText = "Select FileNamecode,filetypecode from FileCoverage where FileNamecode = '" & FileNameCode & "'"
        adapter.Fill(dt4a)
        If dt4a.Rows.Count > 0 Then
            For Each dr In dt4a.Rows
                If dr("FileNamecode") = FileNameCode Then
                    cmbfiletypecode.Text = dr("filetypecode").ToString.Trim
                End If
            Next
        Else
            'cmbFileTypeCode.Text = ""
            cmbFileTypeCode.Text = Form1.Grid1(5, i).Value
        End If
0
Comment
Question by:AlHal2
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 total points
ID: 22834265
One solution would be to use a flag which you can check in the TextChanged() Event:

Public Class Form1
 

    Private MyChange As Boolean = False
 

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

        MyChange = True

        cmbfiletypecode.Text = "something"

    End Sub
 

    Private Sub cmbfiletypecode_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbfiletypecode.TextChanged

        If Not MyChange Then

            MessageBox.Show("TextChanged")

        Else

            MyChange = False

        End If

    End Sub
 

End Class

Open in new window

0
 

Author Closing Comment

by:AlHal2
ID: 31511291
Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now