C# Winforms form losing focus when focusing on child control ... sometimes -


i developing windows mobile 6.5 app , have issues form losing focus when focusing on child control of usercontrol added form... sometimes.

in app navigate between screens adding , removing user controls main form controls collection.

iview nextview = (iview)activator.createinstance(map.view);  this.controls.remove((usercontrol)this.currentview);  this.currentview = nextview;  this.controls.add((usercontrol)this.currentview); 

my basic flow navigation between screens thus:

first add of usercontrol a

  1. initialize usercontrol a
  2. add usercontrol form.controls
  3. focus on grid on a

navigate usercontrol b

  1. initialize usercontrol b
  2. remove usercontrol form.controls
  3. add usercontrol b form.controls

navigate usercontrol a

  1. initialize usercontrol a
  2. remove usercontrol b form.controls
  3. add usercontrol form.controls
  4. focus on grid on a

all works fine , on first add of usercontrol form focused , child control has focus well.

but when navigate usercontrol usercontrol b form loses focus, if try focus on child control in last step. in app has consequence cannot navigate in grid using phone hardware buttons.

any idea on why main form loses focus?

turns out when navigated usercontrol a, triggering navigation event in middle of method, code in usercontrol b continued execute thereby preventing focusing on usercontrol a.

i had hoped when removed usercontrol b form.controls (and disposing it) rest of method wouldn't executed, kind of response.redirect web.

i solved problem adding return; statement after triggering onnavigation event in usercontrol b.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -