Interviews - C# Corner

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

    <P>Hi sapna</P> <P>This click here to resolve your problem.</P> <P><A href="/UploadFile/mahesh/WPFListBox07312008002559AM/WPFListBox.aspx">http://www.c-sharpcorner.com/UploadFile/mahesh/WPFListBox07312008002559AM/WPFListBox.aspx</A></P> <P>&nbsp;</P> <P>Thanks</P>

    • 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<br>

    • 0
  • Ashish Shukla
    Nov, 2010 16

    <P>Write the following in the onSelectedIndexchanged event of listbox<BR>&nbsp; SqlConnection con=new SqlConnection();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //set the connection string below<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; con.ConnectionString = ""; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //set the ID in the below code to the name in the listbox instead of hardcoded value<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand cmdSelect = new SqlCommand("select Picture" +<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; " from TableName where <A href='mailto:ID=@ID",con'>ID=@ID",con</A>);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmdSelect.Parameters.Add("@ID",SqlDbType.Int, 4);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //set the id below<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmdSelect.Parameters["@ID"].Value = "2";</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; con.Open();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; byte[] barrImg = (byte[])cmdSelect.ExecuteScalar();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string strfn = Convert.ToString(DateTime.Now.ToFileTime());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileStream fs = new FileStream(strfn,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileMode.CreateNew, FileAccess.Write);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fs.Write(barrImg, 0, barrImg.Length);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fs.Flush();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fs.Close();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Image1.Image =System.Drawing.Image.FromFile(strfn); </P>

    • 0
  • Sapna
    Nov, 2010 13

    <P><FONT size=2 face=Verdana>Hi,<BR>Anybody help me to solve this problem. Suppose I have a list box with different types of dishes with their images but&nbsp;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.</FONT></P> <P><FONT size=2 face=Verdana>Thanx</FONT></P>

    • 0

Download Free eBooks

Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS