473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

ListView Select Sometimes Fails

rlg
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 1793
Background threads shouldn't be updating UI controls. You should
delegate to the foreground thread in the case that it is the background
thread.
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 {
UpdateItem();
}
}

private void UpdateItem( ) {
lv.Items.Add( data );
....
}
Sincerely,
Bobby

Feb 22 '06 #2
rlg
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.

Sincerely,
Bobby

Feb 23 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike Barrett | last post by:
I have a strange one here and I believe it is a bug. I googled it and saw others having a similar issue and nobody seems to have a fix. I will take another shot. I get this ERROR MESSAGE... ...
0
by: James | last post by:
I am using an sqldatareader and trying to add items from a sql select statement to a listview control. All columns from sql select statement are added into listview except one column that is a sql...
0
by: PeacError | last post by:
Using Microsoft Visual Studio .NET 2003, Visual C# .NET 1.1: I apologize if this question has been addressed elsewhere, but I could not find a reference to it in the search engine for this...
0
by: Mike Barrett | last post by:
I have a strange one here and I believe it is a bug. I googled it and saw others having a similar issue and nobody seems to have a fix. I will take another shot. I get this ERROR MESSAGE... ...
5
by: Phill W. | last post by:
(VB'2003) What's the correct way to remove multiple, selected items from a ListView control (say, from a ContextMenu)? I ask because I'm getting a very annoying ArgumentOutOfRangeException...
5
by: Todd Barlow | last post by:
Hi, When I try to set the BackgroundImage property on a ListView, the project fails to run. Sometimes a generic error message appears telling me that memory might be corrupt. Sometimes the error...
2
by: milindsm | last post by:
Hello, I am working on a task in which I have to read line by line from a text file and add it to listview as an item. Since the file is too large (around 10K-15K lines), it was taking hell lot...
5
by: Joza | last post by:
Hi! I'm getting error when selecting items in ListView control, it says ArguementOutOfRangeExceptions. That happens in SelectIndexChange event. I have tryed with try...catch but there's no...
1
by: NvrBst | last post by:
I have a ListView (VirtualMode) and I want to implement a SelectAll. --1st Atempt-- The standard for loop takes way to long: "for(int i = 0; i < listView1.VirtualListSize - 1; i++)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.