Selectionchnaged vs lostfocus event

khalik

Member
Joined
Jan 25, 2006
Messages
9
Programming Experience
5-10
Hi Guys

I have a choice to make in my windows formi have several comboxs. based on one select the other fill in. and like wise.

if i choose Selection changed event when we bind the datasource it fires too.which in turn is causing issues.

to handle it we had diffrent way. remving handlers binding and add handlers.
or get a boolean variable to trace a chnage.

if we choose lostfocus with out any chnage the whole list get repopulated. which is wrong.

so which event would be a better choice.

thanks
 
You can use Selected changed for both comboboxes without need to add/remove handler. Just add a boolean stating exclusive update. Below is some pseudo code to clarify:
VB.NET:
dim exclusive as boolean = false
 
sub combo1_changed(sender,e) handles combo1.changed
  if exclusive=false then
    exclusive=true 'place block
    'do the update fill of combo2 here
    exclusive=false 'remove block
  end if
end sub
 
sub combo2_changed(sender,e) handles combo2.changed
  if exclusive=false then
    exclusive=true 'place block
    'do the update fill of combo1 here
    exclusive=false 'remove block
  end if
end sub
You see, every time User changes either combobox the code will first block the other event handler from 'doing its thing', fill the other box, then remove the block.
 
Hi John

thanks for replying. that what been doing . when you have to many contrls and code its to much to handle it. i was looking for a better way to handle it.
 
Back
Top