Posted 8 September 2017, 6:20 am EST
Hi Siddharth,
I was unable to reproduce the problem using the following code:
fpSpread1.Sheets.Add(new FarPoint.Win.Spread.SheetView());
fpSpread1.Sheets[0].Cells[1, 1].Text = "Cell1";
fpSpread1.Sheets[0].Cells[2, 2].Text = "Cell2";
fpSpread1.Sheets[1].Cells[1, 1].Text = "Cell3";
fpSpread1.Sheets[1].Cells[2, 2].Text = "Cell4";
Dictionary<Cell, string> dic = new Dictionary<Cell, string>(new CellEqualityComparer());
dic.Add(fpSpread1.Sheets[0].Cells[1, 1], fpSpread1.Sheets[0].Cells[1, 1].Text);
dic.Add(fpSpread1.Sheets[0].Cells[2, 2], fpSpread1.Sheets[0].Cells[2, 2].Text);
dic.Add(fpSpread1.Sheets[1].Cells[1, 1], fpSpread1.Sheets[1].Cells[1, 1].Text);
dic.Add(fpSpread1.Sheets[1].Cells[2, 2], fpSpread1.Sheets[1].Cells[2, 2].Text);
string s;
dic.TryGetValue(fpSpread1.Sheets[1].Cells[2, 2], out s);
MessageBox.Show(s);
When I ran that code, it correctly showed “Cell4” in the message box that popped up. Also, if it makes any difference, I had the code for the CellEqualityComparer class in the same namespace but different class as my form like so:
namespace WinForms_C_Sharp_Test
{
public class CellEqualityComparer : IEqualityComparer<Cell>
{
public bool Equals(Cell x, Cell y)
{
return (x == null && y == null) || (x != null && x.Equals(y));
}
public int GetHashCode(Cell obj)
{
return obj.Row.Index ^ obj.Column.Index;
}
}
public partial class Form1 : Form
{ ....etc....
Let me know if that helps.
Regards,
Kevin