|
-
Jan 18th, 2008, 07:08 AM
#1
Thread Starter
Frenzied Member
Focus problem
I have a treeview and then an array of pictureboxes.
On picHolder(1) I have an array of textboxes.
In the treeview click code I have the following:
Code:
picHolder(1).ZOrder 0
txtAdd(0).SetFocus
cmbGrade.ListIndex = 0
optGender(0).Value = True
When txtAdd(0) has focus the backcolor changes to a light grey colour.
When txtAdd(0) loses focus the backcolor changes to white.
When I click on the treeview this code fires, the txtAdd(0) backcolor changes, but the cursor is not in the textbox.
If I hit the tab key all the textboxes loses focus, but the backcolor stays grey, it goes somewhere, and the second time I hit the tab key the focus is back on txtAdd(0) with the cursor, and then goes through the textboxes as expected.
The treeview tabindex = 0 and the txtAdd(0) tabindex = 1
Anybody got any suggestions why?
Also, why I am on it, are pictureboxes the best way to do this, show different sets of controls?
I think I read somewhere that controls inside of frames have a problem with the resize code. Is this correct?
Thanks
-
Jan 18th, 2008, 08:22 AM
#2
Lively Member
Re: Focus problem
i have encountered something similer
my suggetion i not to use zorder
i normaly use the visible property
althou it takes alot of lines its easy
can somebody tell me a different way ill accept
-
Jan 18th, 2008, 10:40 AM
#3
Thread Starter
Frenzied Member
Re: Focus problem
Thanks astroanu2004 but this didn't make any difference.
-
Jan 18th, 2008, 12:02 PM
#4
Re: Focus problem
 Originally Posted by aikidokid
I have a treeview and then an array of pictureboxes.
On picHolder(1) I have an array of textboxes.
In the treeview click code I have the following:
Code:
picHolder(1).ZOrder 0
txtAdd(0).SetFocus
cmbGrade.ListIndex = 0
optGender(0).Value = True
When txtAdd(0) has focus the backcolor changes to a light grey colour.
When txtAdd(0) loses focus the backcolor changes to white.
When I click on the treeview this code fires, the txtAdd(0) backcolor changes, but the cursor is not in the textbox.
If I hit the tab key all the textboxes loses focus, but the backcolor stays grey, it goes somewhere, and the second time I hit the tab key the focus is back on txtAdd(0) with the cursor, and then goes through the textboxes as expected.
The treeview tabindex = 0 and the txtAdd(0) tabindex = 1
Anybody got any suggestions why?
Also, why I am on it, are pictureboxes the best way to do this, show different sets of controls?
I think I read somewhere that controls inside of frames have a problem with the resize code. Is this correct?
Thanks 
You've told us what happens, but what do you want to have happen? In other words what is the problem?
As far as using pictureboxes as a container for other controls I suppose that's okay, but the normal way is to use frames. And I don't think controls inside a frame will be any more of a problem to resize than those in a picture. How are you doing the resizing?
-
Jan 18th, 2008, 12:55 PM
#5
Thread Starter
Frenzied Member
Re: Focus problem
 Originally Posted by Martin
You've told us what happens, but what do you want to have happen? In other words what is the problem?
The problem is that, although the backcolor is changed, which shows that the GotFocus event is firing, the textbox doesn't seem to have the focus, as the cursor is not in the textbox, and you need to press the tab key twice to get it in there.
 Originally Posted by Martin
As far as using pictureboxes as a container for other controls I suppose that's okay, but the normal way is to use frames. And I don't think controls inside a frame will be any more of a problem to resize than those in a picture. How are you doing the resizing?
I haven't started the resize code yet. This was just something I though I had read here somewhere
-
Jan 18th, 2008, 01:21 PM
#6
Re: Focus problem
Try this instead.
Code:
picHolder(1).ZOrder 0
cmbGrade.ListIndex = 0
optGender(0).Value = True
txtAdd(0).SetFocus
BTW did you create another thread where I suggested you use the Visible property of the picture boxes rather than ZOrder? If so, just out of curiosity, why did you make that choice?
-
Jan 18th, 2008, 02:12 PM
#7
Thread Starter
Frenzied Member
Re: Focus problem
 Originally Posted by MartinLiss
Try this instead.
No, still have to hit the tab twice to get the cursor into the txtAdd(0)
 Originally Posted by MartinLiss
BTW did you create another thread where I suggested you use the Visible property of the picture boxes rather than ZOrder? If so, just out of curiosity, why did you make that choice?
No it wasn't me. Maybe the op in post #2 of this thread.
Would you suggest the visible property be the way to go indtead of the zorder?
If so, just out of curiosity, what are the merits of this way?
-
Jan 18th, 2008, 02:33 PM
#8
Re: Focus problem
With ZOrder you can still tab to a "hidden" control whereas if it's not Visible you can't.
Can you zip up and attach your project please?
-
Jan 18th, 2008, 02:44 PM
#9
Thread Starter
Frenzied Member
Re: Focus problem
I will change the zorder to visible and see if this makes a difference. If not I will post the project in a minute. Thanks
-
Jan 18th, 2008, 03:18 PM
#10
Thread Starter
Frenzied Member
Re: Focus problem
I have used a couple of controls from the vbAccelerator site in this project, so you may have a problem running it.
They are the treeview and the image list.
I have changed it as suggested, but I still get the error.!
To get this problem, when running in IDE, select "Membership" from the treeview, then select "Add New Member".
You will see that the textbox is highlighted, but the focus isn't there until you press the tab key for the second time.
Thanks for the help
Last edited by aikidokid; Jan 18th, 2008 at 03:53 PM.
-
Jan 18th, 2008, 03:31 PM
#11
Re: Focus problem
Since the Treeview is vbAccerator's I can't run the project but maybe I can still help. First, put something like the following in the GotFocus event of txtAdd.
Code:
If Index = 0 Then
Debug.Print "I got the focus"
End If
If that shows that it does get focus (and I assume it will), then put a breakpoint in the LostFocus event and see if the stack will show you how you got there. If it doesn't supply enough info then there's something else we can try.
-
Jan 18th, 2008, 03:58 PM
#12
Thread Starter
Frenzied Member
Re: Focus problem
Now thats interesting.
If I add debug.print it prints to the immediate window, but still the error.
If I add a msgbox, it displays the msgbox and then when I close it the txtAdd(0) has the focus!
Don't know if that gives you any more of a clue!!
-
Jan 18th, 2008, 04:00 PM
#13
Re: Focus problem
Replace the Msgbox with DoEvents and see what happens.
-
Jan 18th, 2008, 04:08 PM
#14
Thread Starter
Frenzied Member
Re: Focus problem
It doesn't get to the breakpoint at the lostfocus event??
-
Jan 18th, 2008, 04:10 PM
#15
Thread Starter
Frenzied Member
Re: Focus problem
 Originally Posted by MartinLiss
Replace the Msgbox with DoEvents and see what happens.
No still the same.
-
Jan 18th, 2008, 04:13 PM
#16
Thread Starter
Frenzied Member
Re: Focus problem
This is my code below:
Treeview code:
Code:
Select Case strChildNode
Case "0-"
'Membership
Select Case strGrandChildNode
Case "0"
'\\Add new
picHolder(1).Visible = True
cmdAdd.Caption = "&Add Member"
Call cmdCancel_Click
cmbGrade.ListIndex = 0
optGender(0).Value = True
lvwMain.Visible = False
txtAdd(0).SetFocus
lngLastHolder = 1
Textbox code:
Code:
Private Sub txtAdd_GotFocus(Index As Integer)
On Error GoTo ErrTrap
Dim i As Long
Select Case Index
Case 0 To 9
For i = 0 To 18
If i = Index Then
DoEvents
lblAdd(Index).FontBold = True
txtAdd(Index).BackColor = &H80000016
Else
lblAdd(i).FontBold = False
If i < 13 Then txtAdd(i).BackColor = vbWhite
End If
Next i
Case 10, 11
For i = 0 To 18
If i = Index + 5 Then
lblAdd(Index + 5).FontBold = True
txtAdd(Index).BackColor = &H80000016
Else
lblAdd(i).FontBold = False
If i < 13 Then txtAdd(i).BackColor = vbWhite
End If
Next i
Case 12
For i = 0 To 18
If i = Index + 6 Then
lblAdd(Index + 6).FontBold = True
txtAdd(Index).BackColor = &H80000016
Else
lblAdd(i).FontBold = False
If i < 13 Then txtAdd(i).BackColor = vbWhite
End If
Next i
End Select
Exit Sub
Code:
Private Sub txtAdd_LostFocus(Index As Integer)
On Error GoTo ErrTrap
'capitalise first letter
Select Case Index
Case 0 To 5
txtAdd(Index).Text = StrConv(txtAdd(Index).Text, vbProperCase)
Case 7 To 12
txtAdd(Index).Text = StrConv(txtAdd(Index).Text, vbProperCase)
End Select
If Index <> 0 Then
Dim i As Long
For i = 0 To 12
txtAdd(i).BackColor = vbWhite
lblAdd(i).FontBold = False
Next i
End If
Exit Sub
-
Jan 18th, 2008, 04:18 PM
#17
Re: Focus problem
Okay last idea...
At the very end of txtAdd_GotFocus put
txtAdd(Index).SetFocus
-
Jan 18th, 2008, 04:35 PM
#18
Thread Starter
Frenzied Member
Re: Focus problem
 Originally Posted by MartinLiss
Okay last idea...
At the very end of txtAdd_GotFocus put
txtAdd(Index).SetFocus
That now gives it the focus as I wanted, but ......
When I tab to go to the next text box, the focus dissapears and then after the second tab it goes back to txtAdd(0) and after that it tabs through as expected.
Thanks for your help anyway Martin, it's much appreciated (and rated).
I will leave the thread open in case anybody else can come up with anything.
-
Jan 20th, 2008, 01:34 PM
#19
Thread Starter
Frenzied Member
Re: Focus problem
It seems like this is something to do with the vbAccelerator treeview, as I have replaced with the VB treeview and the problem doesn't exist.
That said, if anybody has a solution to this I would be interested as the VBA control has a lot of nice features.
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
|