2011-02-10 58 views
1

我在UltraGrid中擁有主/細節關係。我想在用戶點擊行時在新的UltraGrid中顯示子行。我能怎麼做?謝謝從UltraGrid獲取子行

回答

1

您可以處理第一個網格的AfterRowActivate或AfterRowSelected事件,然後用適當的數據填充第二個網格。 如果你把所有父行的數據,你也可以設置列過濾器apropriatly這樣第二格:

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記得重用現有的過濾器或之前將新的過濾器清除過濾條件條件。