How to dynamically enable a control and refresh it into the taborder

  • Thread starter Thread starter kea
  • Start date Start date
K

kea

I have a checkbox and a textbox in a continuous taborder on a form
along with a bunch of other controls. The textbox is disabled.

When I leave the checkbox I want to enable the textbox and move the
focus to it (only if the checkbox.checked=true).

So on the checkbox Leave-event i do the following:
if checkbox.checked=true then
textbox.enabled = true
end if

The result:
the textbox is enabled but the focus is moved to the control after the
textbox.

Question:
Why does the focus not go to the textbox as the textbox is enabled? How
do I get the wanted effect?

I know I can use textbox.focus(), but that gives me problems if the
checkbox is checked and another control subsequent is activated by a
mouseclick. Then the focus will go to the textbox instead of the
control activated by the mouse.
 
kea,
In the old days I would use the checkchanged event. Here's an example.

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CheckBox1.CheckedChanged
TextBox1.Enabled = CheckBox1.Checked
End Sub

Good Luck
DWS
 
I tried to simplify my problem but that backfired!

My problem is that I have a groupbox of radiobuttons and each
radiobutton enables/disables/resets some controls. But I do NOT want
this to happen on the specific radiobutton CheckedChanged-event, but
first when I leave the groupbox. Otherwise I get the sitiation that
when I move through the radiobuttons with presses on the arrow key, the
checkChanged event gets fired for each radiobutton I passes. Thereby I
might reset some controls that already contains data and sholud not be
reset..

I want to find out which radiobutton is checked when I leave the
groupBox and then make the enables/disables/resets of the controls. But
if the next control in the taborder is disabled when I enter my
groupbox of radiobuttons, and I enable it in the leave-event of the
groupbox, it does not give focus to the control I just enabled! WHY
NOT???



DWS skrev:
 
Back
Top