从UltraGrid获取子行

时间:2011-02-10 07:47:56

标签: winforms infragistics ultragrid

我在UltraGrid中有主/细节关系。我想在用户点击行时显示新UltraGrid中的子行。我能怎么做?感谢

1 个答案:

答案 0 :(得分:1)

您可以处理第一个网格的AfterRowActivate或AfterRowSelected事件,然后使用适当的数据填充第二个网格。 如果你有第二个网格中所有Parent行的数据,你也可以像这样设置列过滤器:

private void ugParent_AfterRowActivate(object sender, EventArgs e)
{
  if (this.ugParent.ActiveRow != null)
  {
    //either populate the grid with data specific to the current row:
    //this.ugChilds.DataSource = this.GetChildData(this.ugParent.ActiveRow);
    //or filter the grid
    object key = this.ugParent.ActiveRow.Cells["IDField"].Value;
    this.ugChilds.DisplayLayout.Bands[0].ColumnFilters["RelationField"].FilterConditions.Add(FilterComparisionOperator.Equals, key);
  }
  else
  {
    //clear Child grid if required. If you set datasource to null you will loose all layout and need to relayout the grid on next binding
  }
}

如果使用ColumnFilters,请记住在添加新过滤条件之前重复使用现有过滤器或清除过滤条件。