devexpress - winforms - xtragrid - 对未绑定列数据的过滤引发 NullReference 异常
devexpress - winforms - xtragrid - filtering on unbound column data throws NullReference exception
我有一个我填充的 xtragrid,它有 2 个未绑定的列。一切正常,除了当我去过滤列时,过滤弹出窗口正确显示,但是当我双击一个值时,我得到一个 nullreference 异常。我设法找到了异常的位置,它在我的方法 CustomColumnUnboundData 中,我尝试从当前行获取当前对象,但该对象为空。你能帮助我吗?我究竟做错了什么 ? e.ListSourceRowIndex 或 GetRow() 似乎不适用于过滤...
private void gridView1_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e)
{
GridView gridView = (GridView)sender;
int dataSourceIndex = e.ListSourceRowIndex;
Person person = (Person)gridView.GetRow(dataSourceIndex);
if (e.Column.FieldName == "name" && e.IsGetData)
{
e.Value = person.PersonKey.Name;
}
if (e.Column.FieldName == "surname" && e.IsGetData)
{
e.Value = person.PersonKey.Surname;
}
}
已解决。
private void gridView1_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e)
{
GridView gridView = (GridView)sender;
Person person = e.Row as Person;
//...
}
我有一个我填充的 xtragrid,它有 2 个未绑定的列。一切正常,除了当我去过滤列时,过滤弹出窗口正确显示,但是当我双击一个值时,我得到一个 nullreference 异常。我设法找到了异常的位置,它在我的方法 CustomColumnUnboundData 中,我尝试从当前行获取当前对象,但该对象为空。你能帮助我吗?我究竟做错了什么 ? e.ListSourceRowIndex 或 GetRow() 似乎不适用于过滤...
private void gridView1_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e)
{
GridView gridView = (GridView)sender;
int dataSourceIndex = e.ListSourceRowIndex;
Person person = (Person)gridView.GetRow(dataSourceIndex);
if (e.Column.FieldName == "name" && e.IsGetData)
{
e.Value = person.PersonKey.Name;
}
if (e.Column.FieldName == "surname" && e.IsGetData)
{
e.Value = person.PersonKey.Surname;
}
}
已解决。
private void gridView1_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e)
{
GridView gridView = (GridView)sender;
Person person = e.Row as Person;
//...
}