Sapna
How to display an image from listbox in WPF?
By Sapna in .NET on Nov 13 2010
  • Purushottam Rathore
    Jan, 2011 31

    Hi sapna

    This click here to resolve your problem.

    http://www.c-sharpcorner.com/UploadFile/mahesh/WPFListBox07312008002559AM/WPFListBox.aspx

     

    Thanks

    • 0
  • sumit bakshi
    Nov, 2010 24

    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

    • 0
  • Ashish Shukla
    Nov, 2010 16

    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";

                con.Open();
                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);
                fs.Flush();
                fs.Close();
               
                Image1.Image =System.Drawing.Image.FromFile(strfn);

    • 0
  • Sapna
    Nov, 2010 13

    Hi,
    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.

    Thanx

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS