Windows Forms - Multiple Bound Controls Messing Up Tab Order

J

jehugaleahsa

Hello:

We have a DataGridView on a form and we also have other controls bound
to the same data. When the user clicks on the summary data in the
DataGridView, that item is displayed in the other controls (the
details). The DataGridView is read-only.

We have a tab order set up (correctly) on the form. If you simply hit
tab and go through all of the controls, it will do it in the correct
order.

However, one of our users noticed that if she edited a detail field,
hitting tab would shoot her down to a text box further down the form.
It is always the same text box.

This seems to be taking place when the control is validating. If you
watch carefully, it appears that all of the controls are being
highlighted (the screen sort of flashes). I'm not sure what it is
doing.

There isn't any code in the code-behind that would be selecting all of
the controls. It is just really freaky.
 
J

jehugaleahsa

Hello:

We have a DataGridView on a form and we also have other controls bound
to the same data. When the user clicks on the summary data in the
DataGridView, that item is displayed in the other controls (the
details). The DataGridView is read-only.

We have a tab order set up (correctly) on the form. If you simply hit
tab and go through all of the controls, it will do it in the correct
order.

However, one of our users noticed that if she edited a detail field,
hitting tab would shoot her down to a text box further down the form.
It is always the same text box.

This seems to be taking place when the control is validating. If you
watch carefully, it appears that all of the controls are being
highlighted (the screen sort of flashes). I'm not sure what it is
doing.

There isn't any code in the code-behind that would be selecting all of
the controls. It is just really freaky.

Nevermind. I think I figured it out. There was a piece of code
enabling and disabling the controls depending on whether there were
any items in the list. For some reason, setting Enabled gave the
control focus.
 
P

Peter Duniho

[...]
Nevermind. I think I figured it out. There was a piece of code
enabling and disabling the controls depending on whether there were
any items in the list. For some reason, setting Enabled gave the
control focus.

Disabling a control with focus will cause the next control in tab order to
receive focus. Other than that, the Enabled property shouldn't be
affecting focus.

Pete
 
J

jehugaleahsa

[...]
Nevermind. I think I figured it out. There was a piece of code
enabling and disabling the controls depending on whether there were
any items in the list. For some reason, setting Enabled gave the
control focus.

Disabling a control with focus will cause the next control in tab order to  
receive focus.  Other than that, the Enabled property shouldn't be  
affecting focus.

Pete

That is exactly what was happening. The code was setting focus,
disabling the control and then reenabling it. It would do this one
control after the other until the focus has worked its way down the
line. I had to put a bunch of Enter handlers to see how it was
occurring (looking at the call stack at break points). I fixed the
code that was disabling the controls, since it shouldn't have been
firing. If I hadn't noticed it out of the corner of my eye, I would
probably be still pounded my forehead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top