I am trying to pass in an Entity Framework context to a forms constructor along with a table name, but am stuck trying to get the table object from the context. A BindingSource's datasource should be set to this table's data, DataGridView's DataSource is bound to the BindingSource.
Can anyone help with getting the table data into let's say a List of type tableName and populating the dgv?
public MyForm(T context, string tableName)
{
// use reflection to get the table data from context?
// Doesnt work:
var table = context.GetType().GetProperties().FirstOrDefault(x=>x.Name == tableName);
bindingSource.DataSource = table; //?????
dgvDataviewer.DataSource = bindingSource;
}
Thanks.
Aucun commentaire:
Enregistrer un commentaire