Click here to Skip to main content
15,789,460 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using DataGrid in WPF application, using for loop for retreaving DataGridRow one by one until last, currently i sort datagrid by help of ICollectionView after using ICollectionView my for loop not in working.

XAML Code:

<DataGrid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" x:Name="GridTest"  ItemsSource="{Binding}" AutoGenerateColumns="False" CanUserSortColumns="False" CanUserResizeRows="False" AreRowDetailsFrozen="True" CanUserResizeColumns="False" CanUserDeleteRows="False" IsReadOnly="True">
                    <DataGridTextColumn  Header="SNo" Width="0.25*" Binding="{Binding Path=SNo}" CanUserResize="False" />
                    <DataGridTextColumn Header="SalaryAmt" Width="0.25*" Binding="{Binding Path=SalaryAmt}" CanUserResize="False" />
                    <DataGridTextColumn Header="Name" Width="0.20*" Binding="{Binding Path=Name}" CanUserResize="False"/>
                    <DataGridTextColumn Header="Address" Width="0.30*" Binding="{Binding Path=Address}" CanUserResize="False"/>

code behind:

namespace SortGrid
    public partial class TestDG
    Dictionary<string,> Dict1;
    ObservableCollection<gridstructure> List1 = new ObservableCollection<gridstructure>();
    private ICollectionView _currentView;
    _currentView = CollectionViewSource.GetDefaultView(List1);
    _currentView.SortDescriptions.Add(new SortDescription("SalaryAmt", ListSortDirection.Ascending));
    void DispatchTime_Tick(object sender, EventArgs e)
    GridColors(GridTest_TierColors, GridTest);
    private void GridColors(Brush[] col, DataGrid Grid)
    int colorind = 0;
    for (int rowind = 0; rowind < Grid.Items.Count; rowind++)
    DataGridRow row = (DataGridRow)Grid.ItemContainerGenerator.ContainerFromIndex(rowind);
    if (row != null)
    //conditional formatting here
Updated 27-May-14 9:12am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900