Click here to Skip to main content
15,891,865 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So i have filelistbox

when i click the picture("whatever the extension is") i need to view it in picturebox here is my codes:

VB.NET
Private Sub FileListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileListBox1.SelectedIndexChanged

  Me.PictureBox2.ImageLocation = Application.StartupPath & "\" & FileListBox1.SelectedItem.ToString & "*.jpg; *.gif; *.png";

End Sub


the image wont appear...
Posted
Updated 26-Jul-11 20:07pm
v3

1 solution

This is because you cannot possibly have a file name ending with "*.jpg; *.gif; *.png". :-)

By the way, use string.Format instead of '&'. Multiple concatenation is bad because strings are immutable; each concatenation causes creation of a brand new string and copy operands into it.

[EDIT]
Something like

VB
Me.PictureBox2.ImageLocation = string.Format(
    "{0}{1}{2}",
    Application.StartupPath,
    System.IO.Path.DirectorySeparatorChar,
    FileListBox1.SelectedItem.ToString);

See http://msdn.microsoft.com/en-us/library/system.string.aspx[^].
[END EDIT]

—SA
 
Share this answer
 
v6
Comments
thenorms12 27-Jul-11 1:43am    
where will i put STRING.FORMAT? ill replace all &
thenorms12 27-Jul-11 1:44am    
still wont appear, can u give me the codings?
thenorms12 27-Jul-11 1:44am    
im new to vb.net
Sergey Alexandrovich Kryukov 27-Jul-11 2:15am    
What coding? remove this string at the end; either append one single extension of include extension in the list box items.
String.Format? Look at the class string: http://msdn.microsoft.com/en-us/library/system.string.aspx.
--SA
Sergey Alexandrovich Kryukov 27-Jul-11 2:24am    
Updated, see in [EDIT] brackets. If it makes sense for you, please accept the answer formally (green button).
If not (sigh...), your follow-up questions are welcome.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900