Member Avatar for b1izzard

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

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
commented: Good +2

write your code on combobox_SelectedIndexChanged event

Member Avatar for b1izzard

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

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.

Member Avatar for b1izzard

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.