Hi I have a sfListView,
I am binding to a list of "AgriNotes" each item has a date (DateTime), data(string), and type (string)
When i try and custom group based on the type, i am getting an exception.
Type can be a string from 1 to 11 ("1","2", ... "11")
CS Code Below
listView.DataSource.GroupDescriptors.Add(new GroupDescriptor()
{
PropertyName = "Type",
KeySelector = (object obj1) =>
{
var item = obj1 as AgriNote;
switch(item.Type)
{
case "1":
return "Testing";
case "2":
return "Something else";
default:
return "Other";
}
},
});
Xaml
<listView:SfListView x:Name="listView" AutoFitMode="Height" ItemsSource="{Binding Notes}" BackgroundColor="WhiteSmoke" AllowGroupExpandCollapse="True" >
<listView:SfListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Vertical" Margin="10,10" HorizontalOptions="CenterAndExpand">
<Label Text="{Binding Created}" FontAttributes="Bold" TextColor="Black" FontSize="14"/>
<Label Text="{Binding Note}" TextColor="Black" FontSize="12" LineBreakMode="WordWrap"/>
<Label Text="{Binding Type}" TextColor="Black" FontSize="12" LineBreakMode="WordWrap"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</listView:SfListView.ItemTemplate>
</listView:SfListView>
</Grid>
Stepping through the CS code appears to work fine as in different values are returned fine after the last item i get a Null exception. I am calling this code in the constructor of the page but after ive set the binding context Is that too soon ?
thanks peter