int FindDuplicateCodes()
{
Dictionary<string, int> dict = new Dictionary<string, int>(); // dictionary to map code string to row number.
for (int row = 0; row < grid.Rows.Count; ++row) {
string code = (string) (grid[1, row].Value);
if (dict.ContainsKey(code))
return dict[code]; // already present, return the row number.
else
dict[code] = row;
}
return -1; // no problem.
}