Cause Checkbox to lose focus

  • Thread starter Thread starter OpticTygre
  • Start date Start date
O

OpticTygre

If I create a checkbox dynamically:

Dim NewCheckBox as New Checkbox

Then, I display that checkbox on a form, how can I cause the checkbox to
lose focus after a user clicks on it?

TIA,

-Jason
 
Hello, Jason,

Where do you want the focus to go? Just use the Select method on that
control. E.g.

DesiredControlToHaveFocus.Select

Cheers,
Randy
 
OpticTygre said:
If I create a checkbox dynamically:

Dim NewCheckBox as New Checkbox

Then, I display that checkbox on a form, how can I cause the
checkbox to lose focus after a user clicks on it?

Addhandler NewCheckbox.checkedchanged, addressof OncheckedChanged

'...

private sub OnCheckedChanged (ByVal sender As Object, ByVal e As
System.EventArgs)
'...
end sub


Armin
 
Haha...I would like the focus to go "anywhere" but on that checkbox. The
problem is, the whole form is dynamically generated. The checkbox's checked
field is bound to an object's boolean variable, and that variable happens to
also be bound to a textbox's enabled property. The problem is, the
databinding doesn't fire if I check or uncheck the checkbox .....UNTIL I
actually click *off* the checkbox into another textbox on the form or
something.

Does that make sense?

-Jason
 
Hello, Jason,

Yes, I think I understand what you are saying.

What kind of object is it that the CheckBox is bound to? E.g. does it
have an "Update" method that you can use? If it does, you could invoke
that in an event handler (such as the OnCheckedChanged procedure that
Armin is suggesting).

If there is no way to update the bound object directly, you could try
using the CheckBox's SelectNextControl method in the handler to force
the focus to the next control. (But this isn't a very pleasing
solution, because it would introduce a bit of non-standard behaviour in
the user interface. I would recommend trying to find some sort of
"Update" method solution instead.)

Cheers,
Randy
 
Back
Top