Solved

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

Posted on 2008-10-29
2
735 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

735 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