Solved

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

Posted on 2008-10-29
2
739 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
[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
2 Comments
 
LVL 86

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 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