How to display an image from listbox in WPF?
Posted by Sapna in .NET 2015 on Nov 13, 2010
  • 0
  • 4
  • 7244
Do you know the answer for this question? Post it below.
Posted by Purushottam Rathore on Jan 31, 2011
  • 0

Hi sapna

This click here to resolve your problem.



Posted by sumit bakshi on Nov 24, 2010
  • 0

yes you can do this you can bind listbox based on the datakey name and display image in image controle based on listbox selected value

Posted by Ashish Shukla on Nov 16, 2010
  • 0

Write the following in the onSelectedIndexchanged event of listbox
  SqlConnection con=new SqlConnection();
            //set the connection string below
            con.ConnectionString = "";
            //set the ID in the below code to the name in the listbox instead of hardcoded value
            SqlCommand cmdSelect = new SqlCommand("select Picture" +
              " from TableName where ID=@ID",con);
            cmdSelect.Parameters.Add("@ID",SqlDbType.Int, 4);
            //set the id below
            cmdSelect.Parameters["@ID"].Value = "2";

            byte[] barrImg = (byte[])cmdSelect.ExecuteScalar();
            string strfn = Convert.ToString(DateTime.Now.ToFileTime());
            FileStream fs = new FileStream(strfn,
                              FileMode.CreateNew, FileAccess.Write);
            fs.Write(barrImg, 0, barrImg.Length);
            Image1.Image =System.Drawing.Image.FromFile(strfn);

Posted by Sapna on Nov 13, 2010
  • 0

Anybody help me to solve this problem. Suppose I have a list box with different types of dishes with their images but in the listbox only their names to be shown. Then if i select a dish from the listbox its image should be display outside the listbox.