I have many bindingsource in my winform, and I wanna change my gridview's dataSource dynamically,so I wanna Get bindingSource by there's name. I have find following code to find all bindingSource from my winform,
private IEnumerable<Component> EnumerateComponents()
{
return from field in GetType().GetFields(
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
where typeof(Component).IsAssignableFrom(field.FieldType)
let component = (Component)field.GetValue(this)
where component != null
where component.ToString().Contains("Windows.Forms.BindingSource")
select component;
}
After I got my BindingSourceList I wanna filter one of them by name, But I don't know how to do,please help me, thanks~
IEnumerable<Component> BindingSourceList = EnumerateComponents();
//I wonder find a bindingSource by name, but it doesn't work
BindingSource bb = BindingSourceList.find(a=>a.name=="myBindingSource");
Aucun commentaire:
Enregistrer un commentaire