471,315 Members | 2,275 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,315 software developers and data experts.

ListView Select Sometimes Fails

We have C# 2005 multi-threaded app.

A background thread is processing data and periodically updating the
contents of a ListView. Sometimes, the user clicking on a ListView
item will not select the item (in the MouseClick event,
ListView.SelectedItems.Count = 0).

Initially we assumed it was because the background thread was in the
process of updating the ListView. However, breaking on the first line
of the MouseClick event reveals that the background thread is sleeping
(although perhaps with the timing of the debugger, the background
thread is still the culprit).

What could cause clicking on a ListView item to not select the item?

Thanks in advance...

Feb 22 '06 #1
3 1699
Background threads shouldn't be updating UI controls. You should
delegate to the foreground thread in the case that it is the background
private delegate void UpdateItemHandler( );

private void MethodCalledFromEitherBackgroundOrUIThread( string data
) {
// Check if Method called from the non-UI thread
if( lv.InvokeRequired ) {
lv.Invoke( new UpdateItemHandler( UpdateItem ) );
else {

private void UpdateItem( ) {
lv.Items.Add( data );

Feb 22 '06 #2
Thanks for the input Bobby. We are in fact using BeginInvoke to update
the ListView control from the background data processing thread. Any
ideas why click select may not be working sometimes?

Feb 23 '06 #3
Sorry, without looking at the code and/or debugging, it is very hard to
determine the problem. If I were in this situation, I would start with
a separate dummy project and try to re-create the ListView control and
look at whether the selection is still giving the same behaviour.


Feb 23 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Mike Barrett | last post: by
reply views Thread by Mike Barrett | last post: by
5 posts views Thread by Todd Barlow | last post: by
5 posts views Thread by Joza | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.