2

简单的在这里。我创建了一个数据网格,它有一组行。我想在加载行后根据特定逻辑隐藏特定行?

有任何想法吗?

4

2 回答 2

2

在行加载事件上,即 LoadingRow,因此在每行加载时,您将获得 DataGridRow,其中您有 datacontext。让我们说人(id,名字)

这就是你可以玩的方式..

 private void dataGrid1_LoadingRow(object sender, DataGridRowEventArgs e)
    {
        if(e.Row != null)
        {
            var row = e.Row.DataContext;
            var person = row as Person;
            if (person != null && person.Id == 2)
            {
                (e.Row as DataGridRow).IsEnabled = false;
            }
            if (person != null && person.Id == 1)
            {
                (e.Row as DataGridRow).Visibility = Visibility.Collapsed;
            }
        }
    }
于 2012-07-18T23:33:32.927 回答
0

代码需要调整,但我一直在寻找解决方案,并认为值得发布。

Private Sub gridComments_LoadingRow(sender As Object, e As DataGridRowEventArgs) Handles gridComments.LoadingRow
        Dim row As DataGridRow = e.Row
        For Each col As DataGridColumn In gridComments.Columns
            Dim g1 As FrameworkElement = col.GetCellContent(e.Row)
            Dim c As UIElement = g1.FindName("ChildElementName")
            c.Opacity = 0 'Change the desired properties here
        Next
    End Sub

private void gridComments_LoadingRow(object sender, DataGridRowEventArgs e)
{
    DataGridRow row = e.Row;
    foreach (DataGridColumn col in gridComments.Columns) {
        FrameworkElement g1 = col.GetCellContent(e.Row);
        UIElement c = g1.FindName("ChildElementName");
        c.Opacity = 0;
        //Change the desired properties here
    }
}

有点晚了,但这对我有用。

于 2014-04-16T08:14:12.107 回答