473,385 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem with CanFocus and SetFocus()

I am running into a problem with the CanFocus property not allowing me
to set the focus to a control. The application is a Form which has a
Panel and in the panel are a series of user controls. Each of the user
controls consist of a label and a combobox or text box which is
determined at runtime.

When the application starts, the focus should be set to the first
combobox or text box in the panel. What happens is that the appliation
will start, but the focus will be somewhere else until the user hits
the tab key. At that point, the focus will go to the first entry
control in the panel like it should.

I have gone through the documentation, and found a number of conditions
that must be true in order for a control to get the focus. I have
created a debug log to check these conditions and I get:

MySetFocus(company)
selectable = True
contained = True
Parent Visible & Enabled = True
Visible & Enabled = True
canFocus = False
Handle = 7145084
TabIndex = 0
TabStop = True
set focus = False
entry control set focus = False
entry panel contains focus = False

Other messages in this group and others have suggested that I set
TabIndex to 0 and use the ActiveControl property. Neither of these
have worked. Actually as Panel does not have ActiveControl, I set the
panel to be the active control in the Form and that did not work either.

Sep 11 '06 #1
1 4129
You could try Form.SelectNextControl() at the end of the initialisation.
A bit of a hack but it might be easier then searching for the issue for days.
Ciaran O'Donnell

"Brian" wrote:
I am running into a problem with the CanFocus property not allowing me
to set the focus to a control. The application is a Form which has a
Panel and in the panel are a series of user controls. Each of the user
controls consist of a label and a combobox or text box which is
determined at runtime.

When the application starts, the focus should be set to the first
combobox or text box in the panel. What happens is that the appliation
will start, but the focus will be somewhere else until the user hits
the tab key. At that point, the focus will go to the first entry
control in the panel like it should.

I have gone through the documentation, and found a number of conditions
that must be true in order for a control to get the focus. I have
created a debug log to check these conditions and I get:

MySetFocus(company)
selectable = True
contained = True
Parent Visible & Enabled = True
Visible & Enabled = True
canFocus = False
Handle = 7145084
TabIndex = 0
TabStop = True
set focus = False
entry control set focus = False
entry panel contains focus = False

Other messages in this group and others have suggested that I set
TabIndex to 0 and use the ActiveControl property. Neither of these
have worked. Actually as Panel does not have ActiveControl, I set the
panel to be the active control in the Form and that did not work either.

Sep 12 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Matt Fielder | last post by:
I have developed a custom control to be used in my application. My application includes a form designer, so the control can be hosted while designmode for the control is either true or false,...
4
by: Mad Scientist Jr | last post by:
i am trying to set focus to a specific control depending on the outcome of a validator control and it is not working. none of these methods are working to setfocus: 1....
1
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for...
21
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main...
2
by: hex | last post by:
I put function OnInitDialog in child dialog wich made by class CSecond: BOOL CSecond::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_ed.SetFocus();...
3
by: Jim Devenish | last post by:
In my application vehicles arrive and depart from a workshop. The ArrivalDate and the HandoverDate are each entered. Sometimes the person who should enter the arrival date forgets to do so. ...
1
by: Brian | last post by:
I am running into a problem with the CanFocus property not allowing me to set the focus to a control. The application is a Form which has a Panel and in the panel are a series of user controls. ...
8
by: sara | last post by:
I have a report that runs fine with data. If there is no data, I have its NO Data event sending a MsgBox and cancelling the report. Then it seems I still get the 2501 message on the Open Report...
3
by: srinivasarao yarru | last post by:
hi in access 2003 how we can use the setfocuse property(we have to lostfocuse from one field with in that we have to setfocuse in same field) i am using this code but not setfocuse to same field...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.