[英]bind two bindingsources, which are associated with ORM
I have form with DataGridView. 我有与DataGridView的形式。 This datagrid use this binding:
该数据网格使用以下绑定:
clientBindingSource.DataSource = from asd in db.Clients select new MainGridHelper()
{
Client = asd
};
MainGridHelper have some properties and useful methods. MainGridHelper具有一些属性和有用的方法。 But then I add new client from another form:
但是然后我从另一种形式添加了新客户端:
_client = new Client();
clientBindingSource.DataSource = _client;
//...
DBContext.Clients.InsertOnSubmit(_client);
DBContext.SubmitChanges();
So, I use DataGridView.Refresh() after add client. 因此,添加客户端后,我将使用DataGridView.Refresh()。 I have new null Client in first BindingSource, but row added (empty cells).
我在第一个BindingSource中有新的null客户端,但是添加了行(空单元格)。 I dont want merge MainGridHelper and Clients classes.
我不想合并MainGridHelper和Clients类。 How I can fix this without new LINQ query?
如何在没有新的LINQ查询的情况下解决此问题?
Sorry, if it is an easy question. 抱歉,这是一个简单的问题。
If I understand your question correctly (and that's a big if), just adjust the original LINQ query to exclude the nulls: 如果我正确理解了您的问题(如果这个问题很大的话),那么只需调整原始LINQ查询即可排除空值:
clientBindingSource.DataSource = from asd in db.Clients
where asd != null
select new MainGridHelper()
{
Client = asd
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.