SQLite SELECT query to ListView

0

Hello friends I am trying to show the data of my base SQLite to a listView of my app in Xamarin Forms but I think I'm having problems I do not know if with how I call the data or how I'm trying to insert them into my ListView ... this is what I have.

This is my mistake

public CitaInfo(int ID, string dt) {
  InitializeComponent();
  memberDatabase = new MemberDatabase();
  var citaunica = memberDatabase.CitaUnica(ID);
  ListCitaUnica.ItemsSource = citaunica;
  //DateTime dtx = DateTime.Parse(dt);


}
//Citas crud local
public string AddCita(Cita cita) {
  conn.Insert(cita);
  return "success :3 ";
}

public void DeleteCita(int ID) {
  conn.Delete<Cita>(ID);
}

public Cita CitaUnica(int ID) {
  Cita citaunica=conn.Table<Cita>().FirstOrDefault( ci=> ci.ID==ID);
  return citaunica;
  //return citaunica;
}

public IEnumerable<Cita>GetCitas() {
  var citasx=(from cit in conn.Table<Cita>() select cit);
  return citasx.ToList();
}
<ScrollView>
  <Grid>
    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>

      <Label Grid.Row="0" Margin="10" x:Name="lbl_txt" Text="Datos de Orden" FontSize="25" />

      <ListView x:Name="ListCitaUnica" Grid.Row="1" HorizontalOptions="FillAndExpand" HasUnevenRows="True">

        <ListView.ItemTemplate>
          <DataTemplate>
            <ViewCell>
              <Grid Padding="10">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />

                </Grid.RowDefinitions>


                <Label Text="Fecha" FontSize="Medium" HorizontalOptions="StartAndExpand" Grid.Row="2" Grid.Column="0" FontAttributes="Bold" />
                <Label Text="{Binding razon}" HorizontalOptions="CenterAndExpand" Grid.Row="2" Grid.Column="1" TextColor="Gray" FontAttributes="Bold" />


                <Label Text="Orden" FontSize="Medium" HorizontalOptions="StartAndExpand" Grid.Row="3" Grid.Column="0" FontAttributes="Bold" />
                <Label Text="{Binding descripcion}" HorizontalOptions="CenterAndExpand" Grid.Row="3" TextColor="Blue" Grid.Column="1" FontAttributes="Bold" />


                <Label Text="Itinerario" FontSize="Medium" HorizontalOptions="StartAndExpand" Grid.Row="4" Grid.Column="0" FontAttributes="Bold" />
                <Label Text="{Binding fecha}" HorizontalOptions="CenterAndExpand" Grid.Row="4" Grid.Column="1" TextColor="Gray" FontAttributes="Bold" />

                <Label Text="Medio " FontSize="Medium" HorizontalOptions="StartAndExpand" Grid.Row="5" Grid.Column="0" FontAttributes="Bold" />
                <Label Text="{Binding hora}" HorizontalOptions="CenterAndExpand" Grid.Row="5" TextColor="Orange" Grid.Column="1" FontAttributes="Bold" />



              </Grid>
            </ViewCell>

          </DataTemplate>
        </ListView.ItemTemplate>
      </ListView>




    </Grid>

  </Grid>

</ScrollView>
    
asked by E.Rawrdríguez.Ophanim 02.06.2018 в 02:41
source

1 answer

2

ListView.ItemsSource expects an object that implements IEnumerable . Try assigning a List<Cita> if you implement IEnumerable instead of assigning the object citaunica .

Replaces:

listCitaUnica.ItemsSource = citaunica;

By

listCitaUnica.ItemsSource = new List<Cita>{ citaunica };
    
answered by 02.06.2018 / 03:18
source