S
SeekerOfTruths
Hello.
I'm trying to write a VSTO add-in (my first venture in C# & VSTO) which will
allow me to construct wrapper objects around emails selected by the user (so
that I can hook into open events etc.) and I've run into an issue.
When a user selects multiple items I get a call into my SelectionChange
event hook for each item selected. On the first call the explorer.Selection
collection contains, one item, on the second call it contains two items, and
so on as one would expect.
Since I only want to create a single wrapped object for each selected item,
I had assumed that if I were to keep a copy of the previous selection and
then compare it with the current selection I would be able to determine
whether an item had been added to or removed from the selection, and identify
the object added or removed.
This doesn't seem to be the case however - if I compare each object in the
previous selection to each object in the current selection, I don't find any
matches, despite the fact that the second selection should (in theory)
contain all the objects in the first selection.
I can only assume that I'm making some sort of stupid mistake (see the code
below), because the idea that it's supposed to be that way (and that on each
selection change event I would have to destroy all my wrapped objects and
then re-create them again) just seems plain wrong.
void explorer_SelectionChange()
{
if (null != _priorSelection)
{
foreach (object oldItem in _priorSelection)
{
foreach (object newItem in _explorer.Selection)
{
if (oldItem.Equals(newItem))
{
System.Diagnostics.Trace.WriteLine("Match FOUND");
}
else
{
System.Diagnostics.Trace.WriteLine("No match FOUND");
}
}
}
}
_priorSelection = _explorer.Selection;
}
Any help in pointing out where I've gone wrong would be greatly appreciated!
SeekerOfTruths.
I'm trying to write a VSTO add-in (my first venture in C# & VSTO) which will
allow me to construct wrapper objects around emails selected by the user (so
that I can hook into open events etc.) and I've run into an issue.
When a user selects multiple items I get a call into my SelectionChange
event hook for each item selected. On the first call the explorer.Selection
collection contains, one item, on the second call it contains two items, and
so on as one would expect.
Since I only want to create a single wrapped object for each selected item,
I had assumed that if I were to keep a copy of the previous selection and
then compare it with the current selection I would be able to determine
whether an item had been added to or removed from the selection, and identify
the object added or removed.
This doesn't seem to be the case however - if I compare each object in the
previous selection to each object in the current selection, I don't find any
matches, despite the fact that the second selection should (in theory)
contain all the objects in the first selection.
I can only assume that I'm making some sort of stupid mistake (see the code
below), because the idea that it's supposed to be that way (and that on each
selection change event I would have to destroy all my wrapped objects and
then re-create them again) just seems plain wrong.
void explorer_SelectionChange()
{
if (null != _priorSelection)
{
foreach (object oldItem in _priorSelection)
{
foreach (object newItem in _explorer.Selection)
{
if (oldItem.Equals(newItem))
{
System.Diagnostics.Trace.WriteLine("Match FOUND");
}
else
{
System.Diagnostics.Trace.WriteLine("No match FOUND");
}
}
}
}
_priorSelection = _explorer.Selection;
}
Any help in pointing out where I've gone wrong would be greatly appreciated!
SeekerOfTruths.