Featured post
c# - ListBox throwing ArgumentOutOfRangeException when adding to DataSource -
i'm trying use bindinglist
datasource
listbox
in c# winforms, whenever try add items bindinglist
, argumentoutofrangeexception
thrown. following code demonstrates problem (assume form listbox listbox1
):
bindinglist<string> datasource = new bindinglist<string>(); listbox1.datasource = datasource; datasource.add("test1"); // exception, here.
note if datasource
has items in it, not exception:
bindinglist<string> datasource = new bindinglist<string>(); datasource.add("test1"); listbox1.datasource = datasource; datasource.add("test2"); // appears work correctly.
i can work around problem setting datasource
property null
before adding item, , re-setting datasource
afterward, feels hack, , i'd able avoid doing so.
is there (non-hack) way use empty datasource
on listbox
, such adding items doesn't throw exceptions?
edit: stack trace:
system.windows.forms.dll!system.windows.forms.listbox.selectedindex.set(int value) + 0x1ec bytes
system.windows.forms.dll!system.windows.forms.listcontrol.datamanager_positionchanged(object sender, system.eventargs e) + 0x2e bytes
system.windows.forms.dll!system.windows.forms.currencymanager.onpositionchanged(system.eventargs e) + 0x39 bytes
system.windows.forms.dll!system.windows.forms.currencymanager.changerecordstate(int newposition, bool validating, bool endcurrentedit, bool firepositionchange, bool pulldata) + 0x14f bytes
system.windows.forms.dll!system.windows.forms.currencymanager.list_listchanged(object sender, system.componentmodel.listchangedeventargs e) + 0x2e4 bytes
system.dll!system.componentmodel.bindinglist.onlistchanged(system.componentmodel.listchangedeventargs e) + 0x17 bytes
system.dll!system.componentmodel.bindinglist.firelistchanged(system.componentmodel.listchangedtype type, int index) + 0x35 bytes
system.dll!system.componentmodel.bindinglist.insertitem(int index, system._canon item) + 0x3f bytes
mscorlib.dll!system.collections.objectmodel.collection.add(system._canon item) + 0x76 bytes
it turns out had checked in "exceptions" dialog (debug->exceptions). so, exception exists, (silently) handled .net framework. continuing program execution displays expected results.
- Get link
- X
- Other Apps
Comments
Post a Comment