How to loop over the rows of a WPF toolkit Datagrid

this will return a ‘row’ in your datagrid

public IEnumerable<Microsoft.Windows.Controls.DataGridRow> GetDataGridRows(Microsoft.Windows.Controls.DataGrid grid)
    {
        var itemsSource = grid.ItemsSource as IEnumerable;
        if (null == itemsSource) yield return null;
        foreach (var item in itemsSource)
        {
            var row = grid.ItemContainerGenerator.ContainerFromItem(item) as Microsoft.Windows.Controls.DataGridRow;
            if (null != row) yield return row;
        }
    }

in wpf datagrid, rows are ItemSource.items… no Rows property!

Hope this helps…

Leave a Comment