I want to sort a ListView when it is first loaded. I have implemented the functionality where in the List View can be sorted if the Header columns in the ListView are clicked.
I unable to find a suitable event which I can use to call my sort function. I tried using OnInitialized of the UserControl and Loaded events but it seems the List View is not populated when I call these functions.
I tried GotFocus of ListView. It works but then I have to click on the window to get the sorting done.
I want the sorting to be done as soon as the ListView is loaded.
I am using XML data binding with the List View. The ListView is part of a UserControl. The User Control is hosted in a MMC app.
Please let me know if you need any other information.
<Grid x:Name="GridViewControl" Height="Auto"> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="34"/> </Grid.RowDefinitions>
<local:SortableListView x:Name="ListViewControl" Grid.Row="0" ItemContainerStyle="{DynamicResource StretchedContainerStyle}" ItemTemplateSelector="{DynamicResource myControlTemplateSelector}" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Source={StaticResource dataProvider}, XPath=//CONFIGURATION}">
<ListView.View > <GridView > <local:SortableGridViewColumn Header="ID" HeaderContainerStyle="{StaticResource CustomHeaderStyle}" DisplayMemberBinding="{Binding XPath=./@id}" IsDefaultSortColumn="True" SortPropertyName="@id"/> <local:SortableGridViewColumn Header="VALUE" HeaderContainerStyle="{StaticResource CustomHeaderStyle}" CellTemplateSelector="{DynamicResource myControlTemplateSelector}" SortPropertyName="@value"/> <local:SortableGridViewColumn Header="DATATYPE" HeaderContainerStyle="{StaticResource CustomHeaderStyle}" DisplayMemberBinding="{Binding XPath=./@data_type}" SortPropertyName="@data_type"/> <local:SortableGridViewColumn Header="DESCRIPTION" HeaderContainerStyle="{StaticResource CustomHeaderStyle}" DisplayMemberBinding="{Binding XPath=./@description}" SortPropertyName="@description" Width="{Binding ElementName=ListViewControl, Path=ActualWidth}"/> </GridView> </ListView.View>
</local:SortableListView> <StackPanel Grid.Row="1"> <Button Grid.Row="1" HorizontalAlignment="Stretch" Height="34" HorizontalContentAlignment="Stretch" > <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Center" Orientation="Horizontal" FlowDirection="RightToLeft" Height="30"> <Button Grid.Row="1" Content ="Apply" Padding="0,0,0,0 " Margin="6,2,0,2" Name="btn_Apply" HorizontalAlignment="Right" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Width="132" IsTabStop="True" Click="btn_ApplyClick" Height="24" /> </StackPanel > </Button> </StackPanel >
</Grid>
public
{
}
(
dataView.SortDescriptions.Clear();
dataView.SortDescriptions.Add(sd1);
dataView.SortDescriptions.Add(sd);
dataView.Refresh();
headerClicked.Role !=
||
|| !
newSortColumn =
direction =
Sort(sortPropertyName, direction);
lastSortedOnColumn = sortableGridViewColumn;
lastDirection = direction;
sortableGridViewColumn = gridViewColumn
sortableGridViewColumn =
Sort(sortableGridViewColumn.SortPropertyName,