Calibre2010
Calibre2010

Reputation: 3849

How do I hide a silverlight datagrid row after the row_loading event?

Simple one here. I have created a datagrid, which has a set of rows. I would like to hide specific rows based on particular logic after the rows have been loaded?

Any Ideas?

Upvotes: 2

Views: 1860

Answers (2)

Stephan
Stephan

Reputation: 89

The Code needs to be tweaked but I was looking for a solution to this and thought it was worth posting it.

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
    }
}

A bit late but this worked for me.

Upvotes: 0

MSNetDev
MSNetDev

Reputation: 141

On a Row Loaded Event i.e LoadingRow, so on each row load you get DataGridRow, where you have datacontext. lets say Person (id, name)

this is how you can play on..

 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;
            }
        }
    }

Upvotes: 2

Related Questions