View All Columns in an SQLite Table Using Bindig

1

Forms, I would like to know how to display all table columns in a SQLite database, using the Binding and Listview. I'm using Visual Studio 2017, latest version with Android. All Include, Delete, and Change and List functions are working. I just can not display all the columns in the table. My registration page, CadastroPage.xaml, has the following code:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="AppResumoAulas.Pages.CadastroPage"
             Title="Cadastro de Usuários">
    <ContentPage.ToolbarItems>
        <ToolbarItem Name="Novo" Icon="new48.png" Activated="Novo_Activated" />
    </ContentPage.ToolbarItems>
    <ContentPage.Content>
        <StackLayout>
            <SearchBar Placeholder="Procurar..."  BackgroundColor="Yellow"
               TextChanged="SearchBar_TextChanged" />
            <ListView x:Name="lvwUsuarios">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <TextCell Text="{Binding Usu_Id}" Detail="{Binding Usu_Nome, Usu_Email}" 
                          TextColor="Black" 
                          DetailColor="Silver">
                            <TextCell.ContextActions>
                                <MenuItem Text="Alterar" Clicked="Alterar_Clicked" 
                                  CommandParameter="{Binding .}" />
                                <MenuItem Text="Deletar" Clicked="Deletar_Clicked" 
                                  IsDestructive="True" 
                                  CommandParameter="{Binding .}" />
                            </TextCell.ContextActions>
                        </TextCell>                        
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

The code of the page CadastroPage.xaml.cs, follows below:

using AppResumoAulas.Model;
using System;
using System.Collections.ObjectModel;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace AppResumoAulas.Pages
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class CadastroPage : ContentPage
    {
        private ObservableCollection<Usuarios> _usuarios;

        public CadastroPage ()
        {
            InitializeComponent ();
            var usuarios = App.DataBase.GetUsuarios();
            _usuarios = new ObservableCollection<Usuarios>(usuarios);
            lvwUsuarios.ItemsSource = _usuarios;
        }

        private void Novo_Activated(object sender, EventArgs e)
        {
            Navigation.PushAsync(new IncluirPage(_usuarios));
        }

        private void Alterar_Clicked(object sender, EventArgs e)
        {
            var menuItem = sender as MenuItem;
            var usuario = menuItem.CommandParameter as Usuarios;
            Navigation.PushAsync(new AlterarPage(usuario));
        }

        private async void Deletar_Clicked(object sender, EventArgs e)
        {
            var usuario = (sender as MenuItem).CommandParameter as Usuarios;
            var resposta = await DisplayAlert("Confirma Exclusão deste registro ?", usuario.Usu_Nome, "Sim", "Não");
            if (resposta == true)
            {
                App.DataBase.DeletarUsuario(usuario);
                _usuarios.Remove(usuario);
            }
        }

        private void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
        {
            lvwUsuarios.ItemsSource = App.DataBase.GetUsuarios(e.NewTextValue);
        }
    }
}

The code for creating the Table, follows below:

using SQLite;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace AppResumoAulas.Model
{
    [Table("Usuarios")]
    public class Usuarios : NotifyBase
    {
        [PrimaryKey, AutoIncrement]
        public int Usu_Id { get; set; }

        private string _Usu_Nome;
        [MaxLength(300)]
        public string Usu_Nome
        {
            get { return _Usu_Nome; }
            set
            {
                _Usu_Nome = value;
                OnPropertyChanged();
            }
        }

        private string _Usu_Email;
        [MaxLength(150)]
        public string Usu_Email
        {
            get { return _Usu_Email; }
            set
            {
                _Usu_Email = value;
                OnPropertyChanged();
            }
        }

        private bool _Usu_Ativo;
        public bool Usu_Ativo
        {
            get { return _Usu_Ativo; }
            set
            {
                _Usu_Ativo = value;
                OnPropertyChanged();
            }
        }
    }
}

It seems like a simple problem, for me, that I'm starting, and very complex. I look forward to who can help. Very grateful to all.

    
asked by anonymous 07.11.2018 / 12:58

0 answers