Hi. I'm trying to get a control(combobox) to fire it's validating event by giving it the focus and then removing the focus but this doesn't seem to work. Does anyone know a better way (by which I mean one that works;-))?
Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
If you just want to change the back color on focus or lost focus you can use the events below. Otherwise I need to know what you intention is. Do you want it to turn a different color if it is not the correct format? (Since you usually use a combobox so that you force the user to use the format you want this does not seem likely)
Please give more details on exactly what you are trying to do.
Private Sub ComboBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.GotFocus
ComboBox1.BackColor = Color.Blue
End Sub
Private Sub ComboBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.LostFocus
ComboBox1.BackColor = Color.Red
End Sub
Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
It's a derived combobox in which I have code running in the validating event which calls a routine which checks the data which in turn changes the the colour of the combobox if the choice is incorrect. I need it in the validating event so that I can turn it off with the CausesValidation property if I need to.
This works for me : From a button I set focus and then set focus to another control which fires the Validating event. Can you post you code?
Private Sub ComboBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ComboBox1.Validating
If ComboBox1.SelectedText = "" Then
ComboBox1.BackColor = Color.Red
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ComboBox1.Focus()
ComboBox1.SelectedText = ""
txtAmount.Focus()
End Sub
Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
Yes. This works for me too. I have no idea what I could have been doing differently yesterday(it's the morning of the 5th where I am).Thanks for your help. Have a star.
Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.