Re: Strange Listview item behaviour by Lee
Lee
Tue Feb 22 11:22:58 CST 2005
Lloyd Sheen wrote:
> The updating takes place in a callback to the GUI thread. The problem
> occurs whether I create the ListViewItems in the thread and pass a
> collection of them to the main thread thru a callback or if I create a
> collection of objects which I can use in the callback to the main thread.
> Like I said the strange thing is that the listview items have all the
> subitems but they are not visible.
>
> Lloyd Sheen
>
> "Lee Gillie" <Nospam@me.com> wrote in message
> news:OXwTEgKGFHA.3368@TK2MSFTNGP10.phx.gbl...
>
>>Lloyd Sheen wrote:
>>
>>>I have an application which will scan various folder for files. Each
>>>folder scan will be in it's own thread. The thread iterates the folder
>>>and creates a ListViewItem with various pieces of information about the
>>>files found. The file name and folder name are separated into two
>>>subitems and well as other information.
>>>
>>>When the folder is finished scanning it will then raise an event and pass
>>>an ArrayList of ListViewItems. The GUI will then append those items to
>>>the appropriate ListView.
>>>
>>>The problem is that when adding the items the display of listview items
>>>the FileName which is subitem (0) is always visible but not all subitems
>>>are visible. This is a seemly random problem. I know that the
>>>FolderName is in its subitem since a context menu will cause actions on
>>>the items and needs both the foldername and filename to perform the
>>>action.
>>>
>>>Any ideas?
>>>
>>>Lloyd Sheen
>>
>>From the behaviour it sounds like you may be attempting to update the
>>ListView directly from a separate thread. If so, you need to marshal GUI
>>calls back to the GUI thread.
>>
>>I can think of other possibilities, but again, would need to presume some
>>of your implementation details.
>>
>>HTH - Lee
I have seen things like this happen when doing GUI calls from non-GUI
thread. Sounds like you know you need to use a delegate and form.Invoke
to marshal the call back to the thread. But the "callback to GUI thread"
doesn't sound right. You can debug.WriteLine of the threadID using
routines in Threading to be sure you are on the thread you think you are.
Otherwise I was going to say I wonder if your list is a single instance
whose reference is sent to the GUI thread for painting, and meanwhile is
being cleared in another thread to refresh. You need to make a new
instance of the list. Again, presuming how your code is organized, this
is a guess. There are so many things like this that COULD be the
problem. I don't think the problem is in the framework, and there is not
enough information about what you are doing to know for sure.