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

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

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

Posted by Ashish Shukla on Nov 16, 2010
  • 0

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

Posted by Sapna on Nov 13, 2010
  • 0

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