I don't know the ListView control very well, at all which is part of the
problem, and I've already debugged this to the best of my current ability. I
was hoping by posting here I could get help in isolating the problem enough
to fix it, or find out I'm not using the ListView control correctly.
The test method I posted earlier is being invoked by a TestRunner, I assume.
I am not explicitly creating any other threads.
There class I am testing here is a wrapper around the ListView control
called ListViewLookupWrapper. It's code and inheritance chain is below. One
of the features of the class is to allow the SelectedIndexChanged event to
be delegated as nessary to some method outside of a windows form, where it
can be tested more easily (I have other tests showing that this scheme works
with and without a listView implementation). Another is to capture the
selected item as an ILookupDTO implementation - it is this SelectedItem
method that I'm trying to test. To do that I want to trigger the listview's
own SelectedIndexChanged event. I'm not doing anything with the event here
beyond trying to trigger it, just counting on the ListView to fulfill it's
contract and have the selected item available in it's own SelectedItems
property.
That's where I get to my previous post, as I can't yet prove or disprove
what's going on with the event firing in the debugger after I examine it,
but not otherwise.
Cheers, and thanks for sharing. BH
--------------------------------------------------------------------------------------
public class ListViewLookupWrapper : LookupListBase
{
protected readonly ListView _listView;
public ListViewLookupWrapper(ListView underlyingList) {
_listView = underlyingList;
_ listView.SelectedIndexChanged +=
OnSelectedIndexChanged; -<--XX----- the parent exposes this as a property
}
public override void Add(ILookupDTO lookupDto) {...}
public override void Clear() { _listView.Items.Clear(); }
public override ILookupDTO SelectedItem {
get {
if (_listView.SelectedItems.Count 0) {
var listViewItem = _listView.SelectedItems[0];
var item = new
SimpleLookupDTO(listViewItem.SubItems[0].Text, listViewItem.Text);
return item;
}
return null;
}
}
}
public abstract class LookupListWrapperBase
{
public event EventHandler SelectedIndexChanged;
/// <summary>
/// exposed for inheritors to do testing
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void OnSelectedIndexChanged(object sender, EventArgs e) {
Console.WriteLine("Entering OnSelectedIndexChanged");
if (SelectedIndexChanged != null)
SelectedIndexChanged(sender, e);
}
public abstract ILookupDTO SelectedItem { get; }
public abstract void Add(ILookupDTO lookupDto);
public abstract void Clear();
}
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Sun, 26 Oct 2008 13:27:20 -0700, Berryl Hesh <ef******@yahoo.com>
wrote:
>I wouldn't nomally post this here, as it has something to do with the
ListView control usage I think, or maybe with a race condition or some
windoes messaging. I'm just not sure.
A race condition requires more than one thread. Do you have a second
thread?
You've only posted a single method, which by itself isn't nearly enough to
illustrate a specific problem, never mind a race condition. At a minimum,
you need to more completely describe the code involved here, and really
you should post a concise-but-complete code example that reliably
demonstrates the problem.
I can certainly imagine that if you're calling that code from a thread
other than the one that owns the control, you _might_ get the behavior
you're observing. But speculating isn't a very useful way to debug code.
Pete