|
-
Jul 2nd, 2007, 03:46 AM
#1
Thread Starter
Addicted Member
Alternative from LostFocus
Hi,
For some reason in my application, i don't use LostFocus Event from TextBox, ComboBox, etc. I made some function that able to detect (logically) whenever the user want to leave TextBox, ComboBox, Etc then do whatever thing it should do before leave (TextBox, ComboBox, Etc).
But When user leave TextBox, ComboBox, Etc by mouse my function wasn't able to detect it. How to solve it?
Thanks
PS: sorry for my english.
-
Jul 2nd, 2007, 03:50 AM
#2
Re: Alternative from LostFocus
Could you show us the function please
-
Jul 2nd, 2007, 03:52 AM
#3
Re: Alternative from LostFocus
You can use the Validate event. Its similar to the lostFocus event, but allows you to cancel the focus change.
Example
Code:
Private Sub Text1_Validate(Cancel As Boolean)
If Trim$(Text1.Text) = "" Then Cancel = True
End Sub
-
Jul 2nd, 2007, 04:46 AM
#4
Thread Starter
Addicted Member
Re: Alternative from LostFocus
Hell-Lord:
Nothing fancy in it, and my mistake to say that "i able to detect it when ever the user want to leave TextBox" but i set whenever user hit the prefer key on keydown event it will do what it prefer to do.
Andrew G:
Yes Andrew all those TextBox and ComboBox in my application are using Validate Event. But My Problem is i made my input form is in Row (something similar Microsfot Excell).
User can move to another row only when current row are complete. Problem arise when focus on column 3 then user mistyping "2234" instead "1234". Then user corrected it to "1234" while focus still on those column, user can click away to another row (and validate event --TextBox or ComboBox-- will true) although column 4 and column 5 wasn't fill yet. I hope you got what i mean.
Thanks
Last edited by barianto; Jul 2nd, 2007 at 05:32 AM.
Reason: mistyping
-
Jul 2nd, 2007, 04:57 AM
#5
Re: Alternative from LostFocus
Are the textboxes in an array? What are they called?
-
Jul 2nd, 2007, 05:15 AM
#6
Thread Starter
Addicted Member
Re: Alternative from LostFocus
no Andrew, it;'s not on array. And on those 5 column there are 3 TextBox, 2 ComboBox.
Thanks
-
Jul 2nd, 2007, 06:01 AM
#7
Re: Alternative from LostFocus
Not sure if this is what your looking for 
Code:
Private Sub Text1_GotFocus()
ControlGotFocus 1
End Sub
Private Sub Text2_GotFocus()
ControlGotFocus 2
End Sub
Private Sub Text3_GotFocus()
ControlGotFocus 3
End Sub
Private Sub Combo1_GotFocus()
ControlGotFocus 4
End Sub
Private Sub Combo2_GotFocus()
ControlGotFocus 5
End Sub
Private Sub ControlGotFocus(CtrlNum As Integer)
If Trim(Text1.Text) = "" Then
Text1.SetFocus
ElseIf Trim(Text2.Text) = "" And CtrlNum > 1 Then
Text2.SetFocus
ElseIf Trim(Text3.Text) = "" And CtrlNum > 2 Then
Text3.SetFocus
ElseIf Trim(Combo1.Text) = "" And CtrlNum > 3 Then
Combo1.SetFocus
ElseIf Trim(Combo2.Text) = "" And CtrlNum > 4 Then
Combo2.SetFocus
End If
End Sub
-
Jul 2nd, 2007, 06:14 AM
#8
Re: Alternative from LostFocus
He needs to have a way of tracking at which "row" he is, such as with a control array where he will manipulate/interpret the indices. Using Text1, Text2 will not work as he'd end up making validation code for each "row" with the control names hardcoded as is the case with your ControlGotFocus() procedure Andrew_G. He can't reuse that for the other rows.
Finalize your GUI first barianto... how your implementing the "spreadsheet" or "rows" with textboxes + comboboxes. There has to be a way of interpreting which control instances/indices belong to a "row" or the current group.
Once you've done that, you can create a validation procedure that checks that all controls for the given "row" have valid values. Call this from validate event, if procedure returns false then set the Cancel argument of the validate event. Have all controls call this procedure (they pass their index).
Last edited by leinad31; Jul 2nd, 2007 at 09:12 AM.
-
Jul 2nd, 2007, 06:17 AM
#9
Thread Starter
Addicted Member
Re: Alternative from LostFocus
No, andrew that's not what i want, thanks anyway 
As say in post #4, user still on current column (which could be TextBox or ComboBox) but the value on those TextBox or ComboBox are true for Validate Event. WHen user hit "Enter Key" or other key that has been trap in keydown event, everything will fine -it will be focusing on next column. Problem arise when user leave from that TextBox Or ComboBox to anoher ROW using mouse. it will leave to another Row, and left two other row still hasn't fill yet.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|