2

シンプルなこちら。行のセットを持つデータグリッドを作成しました。行がロードされた後、特定のロジックに基づいて特定の行を非表示にしたいですか?

何か案は?

4

2 に答える 2

2

行ロード イベント、つまり LoadingRow では、行のロードごとに、データ コンテキストがある DataGridRow を取得します。Person(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 に答える