DataGridView DataSource BindingSource, FindCore, BindingSource Find() :
BindingList<YourObject> objectList = new BindingList<YourObject>();
BindingSource source = new BindingSource();
source.DataSource = objectList;
dataGridView1.DataSource = source;
private int GetIndexOfItemById(int id)
{
return source.Find("Id", id);
}
, , ( , , ). , Microsoft . Framework BindingList FindCore, IBindingList() ( , , , ).
IBindingList, Find() ( MSDN).
protected override bool SupportsSearchingCore
{
get
{
return true;
}
}
protected override int FindCore(PropertyDescriptor prop, object key)
{
PropertyInfo propInfo = typeof(T).GetProperty(prop.Name);
T item;
if (key != null)
{
for (int i = 0; i < Count; ++i)
{
item = (T)Items[i];
if (propInfo.GetValue(item, null).Equals(key))
return i;
}
}
return -1;
}
If you use a DataTable as your DataSource, you get the Find () behavior out of the box, but since you say you have a list of user objects, you probably don't know.
source
share