1

I have a query that is getting from the database duplicate info, I read the data from the query with a datareader, then I add the items to a list that as the type history.

As you can see below from the list, the index[0] and index[1] have the same date and day, I want a group then and only shown 1 day and 1 date. To show the data I use a grid inside a listview, you guys can see the example below.

Thanks.

**DataReader:*

while (dr.Read())
            {


                var history= new Models.History();
                history.Description Article = dr["Description Article"].ToString().TrimEnd();
                history.Date= dr["Data"].ToString().TrimEnd();
                history.Day= dr["Day"].ToString().TrimEnd();
                history.Article = dr["Article"].ToString().TrimEnd();

                listEmentas.Add(history);


            }

List with the information:

[0]

  • Date:02-08-2017
  • Article:Article Name1
  • Day:Monday
  • Description Article: Example Description Article.

[1]

  • Date:02-08-2017
  • Article:Article Name2
  • Day:Monday
  • Description Article:Example Description Article.

[2]

  • Date:03-08-2017
  • Article:Article Name1
  • Day:Tuesday
  • Description Article:Example Description Article.

[3]

  • Date:03-08-2017
  • Article:Article Name2
  • Day:Tuesday
  • Description Article:Example Description Article.

Design to show the information:

<ListView x:Name="ListviewHistory">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="300" />
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="16"/>
                            <RowDefinition Height="25"/>
                        </Grid.RowDefinitions>
                        <Label Grid.Row="0" Grid.Column="0" HorizontalOptions="Start" FontSize="12" Text="{Binding Date}"  ></Label>
                        <Label Grid.Row="1" Grid.Column="0" HorizontalOptions="StartAndExpand" Margin="5" FontSize="12" Text="{Binding Article}" FontAttributes="Bold" ></Label>
                        <Label Grid.Row="0" Grid.Column="0" FontSize="12" Text="{Binding Day}" HorizontalOptions="Center"></Label>
                        <Label Grid.Row="0" Grid.Column="1" HorizontalOptions="End" FontSize="12" Text="{Binding Description}" ></Label>

                    </Grid>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

History Class:

public class History
{
    public string Day{ get; set; }
    public string Article { get; set; }
    public string Date { get; set; }
    public string Description Article { get; set; }
}
Beetee
  • 475
  • 1
  • 7
  • 18
Phill
  • 407
  • 1
  • 8
  • 30

0 Answers0