Hi!
I have trouble with 'Contains' method in ListViewItemCol lection class - it
seems like it nevers calls 'Equals' method of class inherited from
ListViewItem... I've found that ListViewItem doesn't override 'Equals'
method, but I _DO_ override it in my class. Have a look at thread:
http://groups.google.com/group/micro...351591db8d07c5
.... and at this piece of code:
using System;
using System.Collecti ons;
using System.Windows. Forms;
namespace CollectionsTest
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
ArrayList ar = new ArrayList();
ar.Add(new MyClass("1"));
ar.Add(new MyClass("2"));
ListView.ListVi ewItemCollectio n col = new ListView.ListVi ewItemCollectio n(new ListView());
col.Add(new MyClass("1"));
col.Add(new MyClass("2"));
System.Console. WriteLine("Cont ains: {0}", ar.Contains(new MyClass("1")));
System.Console. WriteLine("Cont ains: {0}", col.Contains(ne w MyClass("1")));
System.Console. ReadLine();
}
}
class MyClass : System.Windows. Forms.ListViewI tem
{
private string str;
public MyClass(string s)
{
str = s;
}
public override bool Equals(object obj)
{
return str.Equals(obj. ToString());
}
public override int GetHashCode()
{
return str.GetHashCode ();
}
public override string ToString()
{
return str;
}
}
}
ArrayList do calls my 'Equals' method, but ListViewItemsCo llection don't.
Any ideas?
Cheers,
Piotrek