0

I have recently noticed a problem with my listview and my local database using sqlite and Xamarin.Forms, my problem is that when the data of my table is dumped into my ObservableCollection (source item of the ListView) and my List View shows it, the ListView does not shows all the items in that are being supposed to be shown, i have tried by adding dynamically (without a database) items into my List View and by this way the problem seems to disappear, i am sure that the problem is not from my sqlite database beacuse also the problem in one past project that i use an api for getting my info the problem was the same, so i got in the conclusion that the problem was showing external information into my ListView so does anyone knows a possible solution for my problem, by the other way, it would be really helpful if someone could try doing a project with listview and sqlite database.

Important fact: The ListView in my XAML has the Frame controller, so when I don't use it, it shows me all the items from the database, I also don't know why

my current XAML code:

      <ListView
           SeparatorVisibility="None"
                IsGroupingEnabled="True"
                ItemsSource="{Binding TasksCollection}"
                GroupDisplayBinding="{Binding Key}"
                HasUnevenRows="True">
                <ListView.GroupHeaderTemplate>
                    <DataTemplate>
                        <TextCell
                            Text="{Binding Key}"
                            TextColor="White"/>
                    </DataTemplate>
                </ListView.GroupHeaderTemplate>
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <Frame
                                HeightRequest="150"
                                Margin="10"
                                HasShadow="True"
                                CornerRadius="25"
                                BackgroundColor="White">
                                <Grid
                                    Padding="5">
                                <Grid.GestureRecognizers>
                                    <TapGestureRecognizer Command="{Binding GridExpandCommand}"/>
                                </Grid.GestureRecognizers>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="2*"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                    <Label
                                        Grid.Column="0"
                                        Grid.Row="0"
                                        Text="{Binding Name}"
                                        FontAttributes="Bold"
                                        FontSize="Small"
                                        HorizontalOptions="Start"
                                        VerticalOptions="Start">
                                    </Label>
                                    <Image
                                        HeightRequest="25"
                                        Grid.Row="0"
                                        Grid.Column="1"
                                        Source="{Binding TaskIcon}"
                                        HorizontalOptions="End"
                                        VerticalOptions="Start">
                                    </Image>
                                    <Label
                                        Grid.Row="1"
                                        Grid.Column="0"
                                        Text="{Binding Description}"
                                        FontAttributes="Bold"
                                        FontSize="Small"
                                        HorizontalOptions="Start"
                                        VerticalOptions="End">
                                    </Label>
                                    <Button
                                        Grid.Row="1"
                                        Grid.Column="1"
                                        Text="{Binding IsDone}"
                                        TextColor="White"
                                        FontAttributes="Bold"
                                        VerticalOptions="CenterAndExpand"
                                        HorizontalOptions="Center"
                                        FontSize="Small"
                                        CornerRadius="100"
                                        BackgroundColor="LawnGreen">
                                    </Button>
                                </Grid>
                            </Frame>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

My code for adding the items into the collection (I use MvvmHelpers for grouping the data with Grouping) is the following:

foreach (var item in new string[]
            { Languages.HightPriorText, Languages.MediumPriorText, Languages.LessPriorityText })
            {
                var sorted = from tasks in tableList
                             orderby tasks.PriorityLevel // orberby is a keyword of System.Linq namespace
                             group tasks by tasks.PriorityLevel into taskList
                             select new Grouping<string, TaskItemViewModel>(taskList.Key, taskList);
                List<Grouping<string, TaskItemViewModel>> listItems = sorted.Where(t => t.Key == item).ToList();
                foreach (var item2 in listItems)
                    VeryImportantList.Add(item2);
            }

the result is the following:

The image of the result of the app

Any answer i will be noticed about it, and also for any question, it would be awesome some help please!

7
  • Quiroz, I can not reproduce your issue, so can you provide one sample that can reproduce this issue at github, I will download your sample to test. Commented Oct 29, 2019 at 7:16
  • "i am sure that the problem is not from my sqlite database" - you are sure, but you did not check? Could you please verify that the items loaded from your database contain the data you suspect them to contain? Commented Oct 29, 2019 at 13:05
  • Could you please add the code you are using to load the items into your TaskCollection? Commented Oct 29, 2019 at 13:06
  • @PaulKertscher well I have check it and no, the problem seems to not be in my sql database, instead seems to be o the displaying of the items, i have checked it and the data in my collection is correctly dumped but the problem is on the display of it Commented Oct 29, 2019 at 14:29
  • @PaulKertscher yes! I have edited my post and included the code for adding the items Commented Oct 29, 2019 at 14:31

1 Answer 1

2

I have finally solved it, and as i expected was a bug of my current version of Xamarin.Forms (4.0.0) so i update to the newest version of it and everything returns ok, as i expected!

Sign up to request clarification or add additional context in comments.

1 Comment

worked for me too. In my case, the problem was that adding new items withing OnAppearing method was causing the list to have empty cells. Updating Forms fixed the problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.