954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Combo Box Events

Hi I need a help in choosing a combo box event for placing this code. I have tried with Lostfocus,leave,mousefocuschanged,displaymemberchanged like this but nothing works and Lable26(Default I set Visible:false ) is visible even after I select an Item.

If combotype.SelectedIndex = -1 Then
            Label26.Visible = True
            Label26.ForeColor = Color.Red
            Label26.Text = "(Select the Job Category )"
        Else
            Label26.Visible = False
        End If
ravi89
Junior Poster
114 posts since Jun 2009
Reputation Points: 11
Solved Threads: 13
 

The below code will trap the event you are after. However, once an item is selected, it can't be deselected without selecting another value. In other words, SelectedIndex will never again = -1. It would seem that you need to set Label26.visible = true during load and then let this function turn it off after the user selects a value.

Private Sub ComboType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboType.SelectedIndexChanged
        If ComboType.SelectedIndex = -1 Then
            Label26.Visible = True
            Label26.ForeColor = Color.Red
            Label26.Text = "(Select the Job Category )"
        Else
            Label26.Visible = False
        End If
    End Sub
Smith5646
Junior Poster in Training
65 posts since Nov 2009
Reputation Points: 34
Solved Threads: 9
 

write your code on combobox_SelectedIndexChanged event

pritesh2010
Posting Whiz in Training
261 posts since Mar 2010
Reputation Points: 40
Solved Threads: 46
 

thanks smith now the code works fine but I placed the code in lostfocus event

ravi89
Junior Poster
114 posts since Jun 2009
Reputation Points: 11
Solved Threads: 13
 

Be aware that lost focus also fires when the app looses focus, not just when the control looses it. So, if the combobox has focus and they switch apps to read an incoming email, this event will fire.

Smith5646
Junior Poster in Training
65 posts since Nov 2009
Reputation Points: 34
Solved Threads: 9
 
Be aware that lost focus also fires when the app looses focus, not just when the control looses it. So, if the combobox has focus and they switch apps to read an incoming email, this event will fire.

Yes its true, but when i place the code in Selectedindexchanged event means nothing happens when I leave the combo box.

ravi89
Junior Poster
114 posts since Jun 2009
Reputation Points: 11
Solved Threads: 13
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: