Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Force Validating event. 1

Status
Not open for further replies.

Durkin

Programmer
Nov 6, 2000
304
GB
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;-))?

Durkin
 
What event do you want to fire and what would you like to do in that event?

DotNetDoc
M.C.S.D.
---------------------------------------

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
 
The Validating event. And I want to change the backcolor.

Durkin
 
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



DotNetDoc
M.C.S.D.
---------------------------------------

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.

Durkin
 
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

DotNetDoc
M.C.S.D.
---------------------------------------

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.
embarrassed.gif


Durkin
 
I am glad it worked for you. [bigsmile]

DotNetDoc
M.C.S.D.
---------------------------------------

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top