Display an image in a ListView
Julien
156
Reputation points
Hello, I have a Prestashop database and an app that connects to it. With queries, I can display the data on images for example, but I would like to display the image instead of the data. I have defined a ListView there to display the results but only the image information is saved in the database.
My Recherche.xaml.cs
private void VoirImages(object sender, EventArgs e)
{
if (afficherImages.Text == "Voir les images")
{
cn = new MySqlConnection("***************");
try
{
if (cn.State == System.Data.ConnectionState.Closed) { cn.Open(); }
DisplayAlert("Infos:", "Vous êtes connecté", "ok");
afficherImages.Text = "Se déconnecter";
Connecté = true;
imagesbdd.IsVisible = true;
produitsbdd.IsVisible = false;
tracteursbdd.IsVisible = false;
requettebdd.IsVisible = false;
{
if (Connecté)
{
MySqlCommand cmd = new MySqlCommand("SELECT * FROM ps_image_lang WHERE id_image = 24192", cn);
using (MySqlDataReader Lire = cmd.ExecuteReader())
{
var data = new List<Image>();
while (Lire.Read())
{
string id_image = Lire["id_image"].ToString();
string id_lang = Lire["id_lang"].ToString();
string legend = Lire["legend"].ToString();
data.Add(new Image(id_image,id_lang ,legend));
}
imagesbdd.ItemsSource = data;
}
}
else
{
DisplayAlert("Infos:", "Plantage", "Ok");
}
}
}
catch (Exception exp) { DisplayAlert("Info:", "Plantage", "ok"); }
}
else
{
cn.Close();
DisplayAlert("Infos:", "Vous êtes déconnecté", "ok");
afficherImages.Text = "Voir les images";
imagesbdd.IsVisible = false;
produitsbdd.IsVisible = false;
tracteursbdd.IsVisible = false;
requettebdd.IsVisible = false;
}
}
My Recherche.xaml
<ListView x:Name="imagesbdd"
IsVisible="false"
SeparatorColor="DeepSkyBlue"
HorizontalScrollBarVisibility="Always"
HorizontalOptions="Start"
VerticalOptions="Start">
<ListView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Liste des images</x:String>
</x:Array>
</ListView.ItemsSource>
</ListView>
My Image.cs
namespace TractoApp.Data
{
class Image
{
public string id_image;
public string id_lang;
public string legend;
public string Id_image()
{
return id_image;
}
public string Id_lang()
{
return id_lang;
}
public string Legend ()
{
return legend;
}
public Image(string id_image, string id_lang, string legend)
{
this.id_image = id_image;
this.id_lang = id_lang;
this.legend = legend;
}
public override string ToString()
{
return "N° " + id_image + " - " + legend;
}
}
}
How can I convert the id to the address of the image to display it?
Developer technologies .NET Xamarin
5,380 questions
Sign in to answer