【问题标题】:How can I manipulate field properties dynamically?如何动态操作字段属性?
【发布时间】:2015-05-13 10:56:13
【问题描述】:
我有一些字段属性为 Active 的表。这些表使用相同的 RadGridView。 Par 示例表 MyLinqTable。
如何动态更新字段值 Active 的内容?
private void CheckItemChanged()
{
...
bool value = (GridView.CurrentRow.DataBoundItem as MyLinqTable).Active;
(GridView.CurrentRow.DataBoundItem as MyLinqTable).Active = !value;
Db.SubmitChanges();
...
}
【问题讨论】:
标签:
c#
winforms
linq
telerik
【解决方案1】:
这是我的解决方案。您必须检查 DataBoundItem 是否具有名称为“Active”的属性。然后你就可以改变Active的值了。
private void CheckItemChanged()
{
if (
GridView.CurrentRow != null &&
GridView.CurrentRow.DataBoundItem != null &&
GridView.CurrentRow.DataBoundItem.GetType().GetProperty("Active") != null)
{
dynamic dataItem = GridView.CurrentRow.DataBoundItem;
bool value = dataItem.Active;
dataItem.Active = !value;
Db.SubmitChanges();
RefreshItems();
}
}