0

我有 2 个实体,Line其中有多个Tags

在此处输入图像描述

在我的用户界面中,我有一个列表框:

在此处输入图像描述

此列表框绑定到一个投影:

var tagNames = someline.Tags.OrderBy(x=>x.Name).Select(x => x.Name).ToList();
var tagsList = from t in rs.Tags join n in tagNames on t.Name equals n into tags select new { Name = t.Name, IsTagged = tags.Any()};
dgvTags.DataSource = tagsList;

问题 :

我希望选中该复选框,它会自动添加标签 / 或从 Line.Tags 集合中删除未选中的标签。这是否可能以简单的方式进行,还是我必须抓住点击并完成工作并刷新网格?

问题 2... 在执行上述操作之前,我注意到复选框甚至没有选中,这是有原因的吗?

提前谢谢了。

4

1 回答 1

2

If you bind data source to projection you are creating something like readonly (one-way) data binding - there are no entities on behind which could be updated. Moreover this is not a case for some automagic data binding. You are showing information about all tags and selecting which tags must be added to your line. That means that you must manually handle events fired by your UI, get Id of selected tag and use it to add real tag entity to your line.

于 2012-05-01T11:09:11.417 回答