PC Review


Reply
Thread Tools Rate Thread

Amazing!!! ListViewItemCollection interfaces

 
 
Aleksey
Guest
Posts: n/a
 
      20th Dec 2006
Hi, guys!
I'm trying to write collection and in example to do this I observed
ListViewItemCollection public methods and properties. I was impressed when I
find that the methods definitions in ListViewItemCollection different from
methods in interfaces it implements!!!
For example:
IList methods:
int Add(object value);
void Insert(int index, object value);
ListViewItemCollection methods:
public virtual ListViewItem Add(ListViewItem value);
public ListViewItem Insert(int index, ListViewItem
item);

There is no method Add in ListViewItemCollection returns int!!!
May be I'm not qualified enough, but I don't understand how could they
change interface signature!!! It's not about the methods params, becuase I
suppose that they possibly use IList<>, so the parameter may be changed from
Object to ListViewItem... It's about the return value type!!!!
Your opinions... and any way you know to do such a things...

Best regards
Aleksey









 
Reply With Quote
 
 
 
 
Larry Lard
Guest
Posts: n/a
 
      20th Dec 2006
Aleksey wrote:
> Hi, guys!
> I'm trying to write collection and in example to do this I observed
> ListViewItemCollection public methods and properties. I was impressed when I
> find that the methods definitions in ListViewItemCollection different from
> methods in interfaces it implements!!!
> For example:
> IList methods:
> int Add(object value);
> void Insert(int index, object value);
> ListViewItemCollection methods:
> public virtual ListViewItem Add(ListViewItem value);
> public ListViewItem Insert(int index, ListViewItem
> item);
>
> There is no method Add in ListViewItemCollection returns int!!!


ListViewItemCollection implements IList through explicit interface
implementation. You can get at its method int IList.Add(object) by
casting to an IList (although the docs suggest you shouldn't, for this
object).

"Explicit Interface Implementation (C# Programming Guide)"
<http://msdn2.microsoft.com/en-us/library/ms173157(VS.80).aspx>


--
Larry Lard
(E-Mail Removed)
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
 
Reply With Quote
 
Aleksey
Guest
Posts: n/a
 
      20th Dec 2006
I still don't understand how could it be, that when I write
listView1.Items.Add all overloaded Add methods return ListViewItem instead
of int (index) ?!?!

"Larry Lard" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Aleksey wrote:
>> Hi, guys!
>> I'm trying to write collection and in example to do this I observed
>> ListViewItemCollection public methods and properties. I was impressed
>> when I find that the methods definitions in ListViewItemCollection
>> different from methods in interfaces it implements!!!
>> For example:
>> IList methods:
>> int Add(object value);
>> void Insert(int index, object value);
>> ListViewItemCollection methods:
>> public virtual ListViewItem Add(ListViewItem value);
>> public ListViewItem Insert(int index, ListViewItem
>> item);
>>
>> There is no method Add in ListViewItemCollection returns int!!!

>
> ListViewItemCollection implements IList through explicit interface
> implementation. You can get at its method int IList.Add(object) by casting
> to an IList (although the docs suggest you shouldn't, for this object).
>
> "Explicit Interface Implementation (C# Programming Guide)"
> <http://msdn2.microsoft.com/en-us/library/ms173157(VS.80).aspx>
>
>
> --
> Larry Lard
> (E-Mail Removed)
> The address is real, but unread - please reply to the group
> For VB and C# questions - tell us which version



 
Reply With Quote
 
Bruce Wood
Guest
Posts: n/a
 
      20th Dec 2006

Aleksey wrote:
> I still don't understand how could it be, that when I write
> listView1.Items.Add all overloaded Add methods return ListViewItem instead
> of int (index) ?!?!


Yes, but if you do this:

ListViewItemCollection coll = this.listView1.Items;
IList list = coll;

then when you type "list." you will see the other Add method.

 
Reply With Quote
 
raje.in@gmail.com
Guest
Posts: n/a
 
      20th Dec 2006
Hi,

I believe its that "Explicit Interface Implementation" thing. Like
this:

class MyCollection : IList
{
public int Add(MyObject value)
{
...
}

// This can only be accessed using an variable of type IList
ListViewItem IList.Add(object value) // No 'public' and its
'IList'.Add
{
return this.Add((MyObject)value);
}
}

Hope that helped,

Regards
Raje

Aleksey wrote:
> Hi, guys!
> I'm trying to write collection and in example to do this I observed
> ListViewItemCollection public methods and properties. I was impressed when I
> find that the methods definitions in ListViewItemCollection different from
> methods in interfaces it implements!!!
> For example:
> IList methods:
> int Add(object value);
> void Insert(int index, object value);
> ListViewItemCollection methods:
> public virtual ListViewItem Add(ListViewItem value);
> public ListViewItem Insert(int index, ListViewItem
> item);
>
> There is no method Add in ListViewItemCollection returns int!!!
> May be I'm not qualified enough, but I don't understand how could they
> change interface signature!!! It's not about the methods params, becuase I
> suppose that they possibly use IList<>, so the parameter may be changed from
> Object to ListViewItem... It's about the return value type!!!!
> Your opinions... and any way you know to do such a things...
>
> Best regards
> Aleksey


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
arraylist into listviewitemcollection in one step? ohmmega Microsoft VB .NET 1 3rd Aug 2007 12:32 PM
Inherit ListViewItemCollection =?Utf-8?B?ZGFpc3k=?= Microsoft Dot NET Framework Forms 0 26th Jul 2005 09:56 PM
ListViewItemCollection Contains Method Giggsy Microsoft Dot NET Framework Forms 2 11th May 2005 10:02 AM
inheritting from ListView.ListViewItemCollection Chris LaJoie Microsoft C# .NET 0 4th Oct 2003 10:34 AM
A listViewItemCollection question Patrick De Ridder Microsoft C# .NET 2 2nd Sep 2003 10:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:53 AM.