A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Items in consecutive Selection collections not the same?



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 17th 08, 05:12 PM posted to microsoft.public.outlook.program_addins
SeekerOfTruths
external usenet poster
 
Posts: 4
Default Items in consecutive Selection collections not the same?

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.
Ads
  #2  
Old November 17th 08, 07:22 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Items in consecutive Selection collections not the same?

What version of Outlook?

You most likely will not be able to compare the items from the selections
directly using Equals or by comparing hash codes, although you can try hash
codes. Most likely you will have to empty your collection when selection
changes and reconstitute it.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"SeekerOfTruths" wrote in message
...
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.


  #3  
Old November 18th 08, 11:10 AM posted to microsoft.public.outlook.program_addins
SeekerOfTruths
external usenet poster
 
Posts: 4
Default Items in consecutive Selection collections not the same?

Sorry I forgot to mention the Outlook version. It's 2007 SP1.

Thanks for the response though, even if the answer was the one I was hoping
I wouldn't hear!

It really does sound terribly inefficient to have to clear down my
collection of wrapper objects (and undo all their event hooks) each time the
selection changes and then rebuild it again based upon the new selection. If
I select 10 objects by holding down CTRL and clikcing on each object in turn
this will result in 10 calls to on selection change and I will have created
55 wrapper objects in total and destroyed 45 of them.

If the uderyling objects in the selection had stayed the same (perhaps they
are and I just can tell) then I could have just identified the difference
between selections and only created (or destroyed) objects as required.

Oh well, I'll give the hashcodes a go and if that doesn't work then I'll
just have to bite the bullet and go with the clear down and rebuild approach.

Thanks for the assistance though.

SeeketOfTruths.

"Ken Slovak - [MVP - Outlook]" wrote:

What version of Outlook?

You most likely will not be able to compare the items from the selections
directly using Equals or by comparing hash codes, although you can try hash
codes. Most likely you will have to empty your collection when selection
changes and reconstitute it.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"SeekerOfTruths" wrote in message
...
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.



  #4  
Old November 18th 08, 05:30 PM posted to microsoft.public.outlook.program_addins
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Items in consecutive Selection collections not the same?

Compare based on the value of the EntryID property

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"SeekerOfTruths" wrote in message
...
Sorry I forgot to mention the Outlook version. It's 2007 SP1.

Thanks for the response though, even if the answer was the one I was
hoping
I wouldn't hear!

It really does sound terribly inefficient to have to clear down my
collection of wrapper objects (and undo all their event hooks) each time
the
selection changes and then rebuild it again based upon the new selection.
If
I select 10 objects by holding down CTRL and clikcing on each object in
turn
this will result in 10 calls to on selection change and I will have
created
55 wrapper objects in total and destroyed 45 of them.

If the uderyling objects in the selection had stayed the same (perhaps
they
are and I just can tell) then I could have just identified the difference
between selections and only created (or destroyed) objects as required.

Oh well, I'll give the hashcodes a go and if that doesn't work then I'll
just have to bite the bullet and go with the clear down and rebuild
approach.

Thanks for the assistance though.

SeeketOfTruths.

"Ken Slovak - [MVP - Outlook]" wrote:

What version of Outlook?

You most likely will not be able to compare the items from the selections
directly using Equals or by comparing hash codes, although you can try
hash
codes. Most likely you will have to empty your collection when selection
changes and reconstitute it.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"SeekerOfTruths" wrote in
message
...
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.





 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing an 'any' seven consecutive day calendar Craigm Outlook - Calandaring 2 January 6th 08 05:57 PM
Printing Non-consecutive days Clay Outlook - Calandaring 1 August 30th 07 04:46 AM
Performance problem by accessing the folder collections Olivier Langlois Outlook and VBA 6 November 2nd 06 07:20 AM
Getting a task list into an items/selection variable Nomad Outlook and VBA 1 July 7th 06 09:10 PM
Outlook should allow non-consecutive recurring meeting dates. DP Outlook - Calandaring 3 April 10th 06 07:24 PM


All times are GMT +1. The time now is 06:47 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.