none
ComboBox TextChanged event not firing RRS feed

  • Question

  • Hi,

    I have two combo boxes, both data bound.

    The items of second combo box changes on changing the value of the first one, but the TextChanged event is not firing.

    Please tell me which event is fired when the text property is changed for a data bound combo box.


    Shishir

    Friday, August 24, 2018 10:49 AM

All replies

  • This works where both ComboBox controls are populated with strings.

    Public Class Form2
        Private Sub ComboBox1_TextChanged(sender As Object, e As EventArgs) _
            Handles ComboBox1.TextChanged
    
            Dim value = ComboBox2.FindString(ComboBox1.Text)
            If value > -1 Then
                ComboBox2.SelectedIndex = value
            End If
    
        End Sub
    End Class


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, August 24, 2018 12:04 PM
    Moderator
  • Show some details about the data source and the binding. How to reproduce the problem?


    Friday, August 24, 2018 12:32 PM
  • Hi,

    I am talking about the TextChanged event of combobox2.

    There is a parent child relationship between the two comboboxes. Every change in Combobox1 fills combobox2 with a new set of items but the TextChanged event of combobox2 is not fired.


    Shishir

    Friday, August 24, 2018 12:40 PM
  • Hi,

    I am talking about the TextChanged event of combobox2.

    There is a parent child relationship between the two comboboxes. Every change in Combobox1 fills combobox2 with a new set of items but the TextChanged event of combobox2 is not fired.


    Shishir

    That does not make sense, to fill ComboBox2 based on ComboBox1 what I shows would provide the path to this so why use TextChanged in ComboBox2 ? as already mentioned let;s see the code.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, August 24, 2018 12:51 PM
    Moderator
  • Given we have no idea what your relationship looks like, or your event code, or your reasoning,  I am going to just assume that after a long and complicated operation, Combobox2 entered this world through C-Section, but is now up for adoption because Combobox1 is addicted to heroin. It's now up to combobox2 to face this world alone.

    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi


    • Edited by Gtripodi Friday, August 24, 2018 12:58 PM
    Friday, August 24, 2018 12:58 PM
  • Here is the code used for binding the two comboboxes:

    Dim adpClass As New SqlDataAdapter("select class_id,  class_name from sl_class where status=1", conSMS.sqlConn)
    Dim adpSName As New SqlDataAdapter("select student_id, Name, class from sl_student order by 2", conSMS.sqlConn)
    Dim dsCS As New DataSet

    dsCS.Clear()
    dsCS.Relations.Clear()

    adpClass.Fill(dsCS, "CL")
    adpSName.Fill(dsCS, "SN")

    dsCS.Relations.Add("drCS", dsCS.Tables(0).Columns(0), dsCS.Tables(1).Columns(2), False)

    cmbSClass_s2.DataSource = dsCS
    cmbSClass_s2.ValueMember = "CL.class_id"
    cmbSClass_s2.DisplayMember = "CL.class_name"

    cmbSName_s2.DataSource = dsCS
    cmbSName_s2.ValueMember = "CL.drCS.student_id"
    cmbSName_s2.DisplayMember = "CL.drCS.name"



    Shishir

    Friday, August 24, 2018 1:19 PM
  • How about some event codes? Im lost on what youre doing, usually I remove events like that from firing, why do you want textchanged event to fire when changing(what event) on combo1. 

    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi

    Friday, August 24, 2018 1:35 PM
  • As a workaround, you can use a Timer that detects the changes. It is also possible to handle the WM_SETTEXT message in a custom control, inherited from ComboBox. (Unless you find the appropriate solution).

    If you believe that it is a defect, I think you can report it (probably to https://developercommunity.visualstudio.com), preparing a DataSet from some strings instead of database.


    Friday, August 24, 2018 6:47 PM