<ListView x:Name="listDonne" HorizontalAlignment="Left" Height="246" Margin="20,371,0,0" VerticalAlignment="Top" Width="358" Cursor="Hand"> <ListView.View> <GridView> <GridViewColumn Header="ID"> <GridViewColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding ID}" Margin="30,0,0,0" HorizontalAlignment="Stretch"/> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn Header="NOM"> <GridViewColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Nom}" Margin="30,0,0,0" HorizontalAlignment="Stretch"/> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> ................ <GridViewColumn Header="FRUIT"> <GridViewColumn.CellTemplate> <DataTemplate> <Image Source="{Binding image}"/> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> ................. </GridView> </ListView.View> </ListView>
public class Arbre { public int ID { get; set; } public string Nom { get; set; } public int Age { get; set; } public BitmapImage image { get; set; } public string Desc { get; set; } public string Comes { get; set; } }
public partial class TestWindow1 : Window { OpenFileDialog fd = new OpenFileDialog(); List<Arbre> arbre = new List<Arbre>(); Convertisseur cnt = new Convertisseur(); public TestWindow1() { InitializeComponent(); LordData(); } //recuperation des données void LordData() { try { using (SqlConnection cnx = new SqlConnection(Properties.Settings.Default.ChaineDeConnxion)) { cnx.Open(); byte[] im = null; ListViewItem list = new ListViewItem(); using (SqlCommand cmd = new SqlCommand("select *from Arbres", cnx)) { SqlDataReader rd = cmd.ExecuteReader(); while (rd.Read()) { arbre.Add(new Arbre() { ID = Convert.ToInt32(rd[0]), Nom = rd[1].ToString(), Age = Convert.ToInt32(rd[2]), image =new BitmapImage(new Uri( Convert.ToString(rd[3]))), Desc = rd[4].ToString(), Comes = rd[5].ToString() }); }//remplissage de ma ListView listDonne.ItemsSource = arbre; rd.Close(); } cnx.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public partial class TestWindow1 : Window { OpenFileDialog fd = new OpenFileDialog(); List<Arbre> arbre = new List<Arbre>(); Convertisseur cnt = new Convertisseur(); public TestWindow1() { InitializeComponent(); LordData(); } //recuperation des données void LordData() { try { using (SqlConnection cnx = new SqlConnection(Properties.Settings.Default.ChaineDeConnxion)) { cnx.Open(); byte[] im = null; ListViewItem list = new ListViewItem(); using (SqlCommand cmd = new SqlCommand("select *from Arbres", cnx)) { SqlDataReader rd = cmd.ExecuteReader(); while (rd.Read()) { arbre.Add(new Arbre() { ID = Convert.ToInt32(rd[0]), Nom = rd[1].ToString(), Age = Convert.ToInt32(rd[2]), image =new BitmapImage(new Uri( Convert.ToString(rd[3]))), Desc = rd[4].ToString(), Comes = rd[5].ToString() }); }
//remplissage de ma ListView listDonne.ItemsSource = arbre; rd.Close(); } cnx.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }