I have a simple class called Tuple. which looks like this :
class tuple
{
string name;
string code
}
i inserted few of these items into a combobox, now when i want to select through the code some item, i try to write
myComboBox.selectedItem = new tuple("Hello" , "5");
and of course it doesn’t work at all and the selected item doesn’t change.
let’s assume the items list of the combobox contains an item that looks like this, how can he compare the items ?
i inherited iComparable and implemented it, but unfortunately he doesn’t use it at all..
how can i set the selected item ? should i run an all the items with a loop and compare them by myself ?
thanks
You’ll need to override the
Equalsmethod in order to provide a custom comparison that is able to assert if twotupleinstance represent the same value.You should also check the following MSDN entries about how to properly override the
Equalsmethod:Implementing the Equals Method
Guidelines for Implementing Equals and the Equality Operator (==)
Microsoft Code Analysis Rule about overriding
GetHashCodewhenever you overrideEquals:CA2218: Override GetHashCode on overriding Equals