public override object Lookup(int column, string keyNames, object[] keyValues) { lock (LookupDataViews) //Make sure no 2 threads try to use LookupDataViews at the same time. { TLookupCache LookupDV; if (!LookupDataViews.TryGetValue(keyNames, out LookupDV)) { if (LookupDataViews.Count > 10) { LookupDataViews.Clear(); //Avoid too many indexes. } LookupDV = new TLookupCache(new DataView(Data, String.Empty, keyNames, DataViewRowState.CurrentRows)); LookupDataViews.Add(keyNames, LookupDV); } if (LookupDV.EqualKeys(keyValues)) { return(LookupDV.LastRow.Row[column]); } int row = LookupDV.dv.Find(keyValues); if (row < 0) { return(null); } LookupDV.LastRow = LookupDV.dv[row]; LookupDV.LastKeyValues = keyValues; return(LookupDV.LastRow.Row[column]); } }