Using ListBox DataSouce causes scrolling headache

G

Guest

I have a ListBox that uses a DataSource bound to an "ActiveArrayList" class I implemented using CollectionBase and IBindingList

As I add new items to my ActiveArrayList, my ListBox is updated with the new row, but the selected row is always forced to scroll into view (by the CurrencyManager I guess). Also, there is apparently no way to have a databound ListBox without enabling selection

Because I'm adding new items to the list at a rate of about 3 per second, the ListBox selection appears to jump around a lot. Not only that, but it's virtually impossible to change the selection with a mouse click (the selection just jumps back to the previous selection). Even worse, I can't scroll the list because any attempt to click in or drag the scroll bar is overriden by whatever is forcing the selected item to scroll into view when a new item is added

None of this happens when I use the ListBox without a DataSource.

Is there some way to disable whatever is forcing the selection to scroll into view when I add a new item? I think if I could do that, it would make everything work OK. If I can't do that, then I would say the DataSouce feature of the ListBox is broken and should be fixed.
 
Y

Ying-Shen Yu[MSFT]

Hi,
Unfortunately, when using databinding, if there is a change on the
underlying datasource, all items in textbox will be cleared and re-added.
The listbox has already tried to preserve the state between this process,
it saves the selected index before resetting data and set selected index
back after re-adding, however it's not possible to save and restore the
scroll postion of the listbox.


generally, you may try using the listbox in unbound mode, if your scenario,
really needs a bounded listbox, Maybe you may try overriding the
ListBox.SetItemsCore(IList items) method to change the data adding behavior
in databinding, you need P/Invoke to add/delete the listbox directly since
in databinding the Items collection is not changable.
And as the document says, this method is for infrastructure use, you are
overriding it at your own risk.

Hope it helps.

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
J

James O

Thanks for the reply. Although this is not the answer I
was hoping for, it's still helpful to know that it's
broken and I should pursue other options.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top