System.Windows.Forms.ListBox bug with BeginUpdate()/EndUpdate()
Came across an annoying bug with ListBox. If you use BeginUpdate() and EndUpdate() and only add a single item to a cleared Item collection, then that Item does not show up on Refresh. However if you leave the BeginUpdate()/EndUpdate() out, it works fine, resulting in a need for code like this:
listBox.Items.Clear(); if( itemList.Count > 1 ) { //only use the Begin/End cycle if we have more than one item itemList.BeginUpdate(); } foreach( object item in itemList ) { listBox.Items.Add(item); } if( group.Strings.Count > 1 ) { //only use the Begin/End cycle if we have more than one item mStrings.EndUpdate(); } listBox.Refresh();

0 Comments:
Post a Comment
<< Home