In short
我有自定义集合,我想使用数据网格显示和编辑(GUI 方式)。第一部分——展示——有效。第二个——编辑——则不然。
第一次尝试交互式编辑(由用户)时,我收到错误异常:
'EditItem' is not allowed for this view.
从表面上看,该集合似乎已准备好进行编辑,因此使用datagrid进行编辑的条件是什么?
Details
我的自定义集合是二维 bool 数组,实现 IEditableObject。我手动创建数据网格列,然后将我的集合分配给数据网格的 ItemSource。两列和整个数据网格的 IsReadonly 设置为 false。
void SetupDisplay()
{
ConnectionsGrid.BeginInit();
ConnectionsGrid.Columns.Clear();
int count = 0;
foreach (var conn in Connections)
{
var col = new DataGridCheckBoxColumn();
col.IsReadOnly = false;
col.Header = count == 0 ? "gr" : count.ToString();
col.Binding = new Binding(String.Format("[{0}]", count));
ConnectionsGrid.Columns.Add(col);
++count;
}
ConnectionsGrid.IsReadOnly = false;
ConnectionsGrid.EndInit();
ConnectionsGrid.ItemsSource = Connections;
UpdateDisplay();
}
void UpdateDisplay()
{
this.Dispatcher.BeginInvoke(DispatcherPriority.DataBind, doUpdateDisplay);
}
void doUpdateDisplay()
{
foreach (var row in Enumerable.Range(0, ConnectionsGrid.Items.Count))
{
ConnectionsGrid.GetRow(row).Header = row == 0 ? "gr" : row.ToString();
}
}
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)