I will answer in C#, if you don't understand tell me. Your problem is the following: (1) Contains uses Equals. (2)
GridItem g1 = new GridItem("bla", "bla");
GridItem g2 = new GridItem("bla", "bla");
if (g1.Equals(g2))
Response.Write("equal");
else
Response.Write("not equal");
This returns not equal. Why? If the GridItem does not implement an Equals function, it will check the equality of the HashCode.
Response.Write(g1.GetHashCode().ToString());
Response.Write(g2.GetHashCode().ToString());
Two different hashcodes. So how do we solve this? Add an Equals function to your GridItem:
public override bool Equals(object obj)
{
if (obj == null && this == null)
return true;
else if ( (obj == null && this != null ) || (obj != null && this == null))
return false;
else if (this.Brand == ((GridItem)obj).Brand && this.Category == ((GridItem)obj).Category)
return true;
else
return false;
}
This first checks if the object are null, and then checks if the contents of the objects are the same. Now the above equation of g1.Equals(g2), will return true.