c# - BindingList and ListBox behaviour -
i have listbox bound bindinglist collection. works great.
my grief occurs when first item enters collection. default behavior of listbox select item - yet, not raise selectedindexchanged event. assume because selectedindex set null; on becoming null, index isn't changed; rather assigned. how can stop default behavior of selecting (highlighting) first initial item added listbox?
if assumption wrong, please shed light?
update
here core parts of code far.
public uavcontrolform() { initializecomponent(); _controlfacade = new uavcontroller.facade.controlfacade(); updateflightuavlistbox(); } private void updateflightuavlistbox() { lsbflightuavs.datasource = _controlfacade.getflightuavtally(); lsbflightuavs.displaymember = "name"; } private static bindinglist<flightuav> _flightuavtally = new bindinglist<flightuav>(); public bindinglist<flightuav> flightuavtally { { return _flightuavtally; } } public void addflightuav(double[] latlonandalt) { flightuav flightuav = new flightuav(); flightuav.latitude = latlonandalt[0]; flightuav.longitude = latlonandalt[1]; flightuav.altitude = latlonandalt[2]; _flightuavtally.add(flightuav); utilstk.injectaircraftintostk(flightuav.name); flightuav.setflightdefaults(); playscenario(); }
update:
so, setting lsbflightuavs.selectedindex = -1
solves problem. above method addflightuav()
called button's onclick handler in second form main form. how can call lsbflightuavs.selectedindex = -1
second form when addflightuav()
method returns? know can make listbox static, seems bad practice me.. more elegant solution?
using winforms, implemented singleton pattern. enabled me access listbox control second form.
form 1
private static uavcontrolform _instance = new uavcontrolform(); private uavcontrolform() { initializecomponent(); } public static uavcontrolform instance { { return _instance; } } public listbox flightuavlistbox { { return lsbflightuavs; } }
form 2
uavcontrolform.instance.flightuavlistbox.selectedindex = -1;
Comments
Post a Comment