CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2001
    Location
    County Durham, England
    Posts
    238

    Combo Box Nightmare

    I have a Combo Box which is part of a Control Array. I am trying to code the change event of the combo box but when I do actually re-select an item from the list the Change Event is not initiated, what am I doing wrong ?

    Work is necessary for man. Man invented the alarm clock.

  2. #2
    Join Date
    Jul 1999
    Posts
    17

    Re: Combo Box Nightmare

    Hi,

    When you select an item from the combo, click event is fired. You need to handle that.

    Regards,
    Lalitha


  3. #3
    Join Date
    Mar 2001
    Location
    County Durham, England
    Posts
    238

    Re: Combo Box Nightmare

    But you can click the combo box without actually changing the contents of the Text, Do I have to record the Text on the click and then use the lost focus to re-check the contents to see if its changed, if so why is the change event there ?

    Work is necessary for man. Man invented the alarm clock.

  4. #4
    Join Date
    Jul 1999
    Posts
    17

    Re: Combo Box Nightmare

    Hi...

    Also wnated to add one more..A combo box is an editable list box. So the user can enter in the edit box. Change event will be fired when the user enters text in the combo.

    Regards,
    Lalitha


  5. #5
    Join Date
    Jul 1999
    Posts
    17

    Re: Combo Box Nightmare

    The text selected in the combo at moment can be got from the text property.

    To clearly understand when the change event occurs, open a new vb project, add a combo and a button to it and paste the code below....

    Private Sub Combo1_Change()
    MsgBox "Change"
    End Sub

    Private Sub Combo1_Click()
    MsgBox "click"
    End Sub

    Private Sub Command1_Click()
    MsgBox Me.Combo1.Text
    End Sub

    Private Sub Form_Load()
    me.Combo1.AddItem "my"
    me.Combo1.AddItem "combo"
    me.Combo1.AddItem "test"
    End Sub


    Then type in the text box in combo....The message "Change" will be displayed. Select some item ...then click on the button....the text selected will be displayed.

    The change event may be used to display the item starting with the typed characters as and when the user types. Eg. when the user starts typing "t" we can display test.

    Hope thsi answers your question

    Regards,
    Lalitha


  6. #6
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Combo Box Nightmare

    The change event is used to record changes to the text box of a combobox.
    To detect clicking a List Item of a combobox use the _Click event. Here is a small demo

    option Explicit

    private Sub Combo1_Change()
    MsgBox "Change Event " & Combo1.Text

    End Sub

    private Sub Combo1_Click()
    MsgBox "Click Event " & Combo1.List(Combo1.ListIndex)

    End Sub

    private Sub Form_Load()
    Dim x
    for x = 1 to 10
    Combo1.AddItem x
    next x

    End Sub
    \



    John G

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured