|
-
Jan 19th, 2010, 08:59 PM
#1
Thread Starter
Member
list box
hey guys i got my list box working.but it lists the path and the name..
ist it possible list only the image it self?
Code:
Imports System.IO
Public Class Form3
Private Sub FindFiles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindFiles.Click
Dim thefiles() As String
'change the path to a path that exists in your machine
thefiles = Directory.GetFiles("C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\trainersTool\images\plyo")
Me.ListBox1.DataSource = thefiles
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
End Sub
End Class
-
Jan 19th, 2010, 09:22 PM
#2
Re: list box
try this:
vb Code:
Dim di As New IO.DirectoryInfo("C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\trainersTool\images\plyo")
Dim theFiles = (From fi In di.GetFiles _
Select fi.Name).ToList
Me.ListBox1.DataSource = theFiles
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 19th, 2010, 09:28 PM
#3
Thread Starter
Member
Re: list box
cool this shows the file name.now can i get the pic to show?
-
Jan 19th, 2010, 09:42 PM
#4
Re: list box
 Originally Posted by .paul.
try this:
vb Code:
Dim di As New IO.DirectoryInfo("C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\trainersTool\images\plyo") Dim theFiles = (From fi In di.GetFiles _ Select fi.Name).ToList Me.ListBox1.DataSource = theFiles
There's not actually any need to use LINQ here:
vb.net Code:
Me.ListBox1.DisplayMember = "Name" Me.ListBox1.DataSource = di.GetFiles()
The advantage of binding is that you still have the full FileInfo object available. You might also set the ValueMember to "FullName" and then you can get the full path of the selected file from the SelectedValue.
-
Jan 19th, 2010, 09:46 PM
#5
Thread Starter
Member
Re: list box
true..but i still need to figure out how to show the image..
-
Jan 19th, 2010, 10:08 PM
#6
Re: list box
ListBoxes don't show images. You'd have to either customise a ListBox or use a different control(s). How you display the images aside, how you get the Images is to first get the file paths, then call Image.FromFile for each one, e.g.
vb Code:
Dim paths As String() = IO.Directory.GetFiles("folder path here") Dim upperBound As Integer = paths.GetUpperBound(0) Dim images(upperBound) As Image For index As Integer = 0 To upperBound images(index) = Image.FromFile(paths(index)) Next
-
Jan 20th, 2010, 01:47 AM
#7
Re: list box
you could use a datagridview rather than a listbox. i'd still recommend using LINQ in vb2008:
vb Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'this gets all the icons from a folder containing icons
'displaying the filename in the first column in the dgv
'the full path to the icon in the hidden second column
'+ the actual icon in the third column
Dim files = (From fi As IO.FileInfo In New IO.DirectoryInfo("C:\Users\Paul\Pictures\ICO").GetFiles _
Select New With { _
.filename = fi.Name,
.fullName = fi.FullName,
.image = Image.FromFile(fi.FullName) _
}).ToList
DataGridView1.DataSource = files
DataGridView1.Columns(1).Visible = False
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 20th, 2010, 02:26 AM
#8
Re: list box
 Originally Posted by .paul.
i'd still recommend using LINQ in vb2008
In that case, yes, because it adds value. In the other case it didn't.
-
Jan 20th, 2010, 06:14 AM
#9
Thread Starter
Member
Re: list box
 Originally Posted by .paul.
you could use a datagridview rather than a listbox. i'd still recommend using LINQ in vb2008:
vb Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'this gets all the icons from a folder containing icons
'displaying the filename in the first column in the dgv
'the full path to the icon in the hidden second column
'+ the actual icon in the third column
Dim files = (From fi As IO.FileInfo In New IO.DirectoryInfo("C:\Users\Paul\Pictures\ICO").GetFiles _
Select New With { _
.filename = fi.Name,
.fullName = fi.FullName,
.image = Image.FromFile(fi.FullName) _
}).ToList
DataGridView1.DataSource = files
DataGridView1.Columns(1).Visible = False
End Sub
End Class
this form is giving me errors?
Error 2 Expression expected. C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\WindowsApplication1\WindowsApplication1\Form4.vb 26 41 WindowsApplication1
Error 3 Leading '.' or '!' can only appear inside a 'With' statement. C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\WindowsApplication1\WindowsApplication1\Form4.vb 27 22 WindowsApplication1
Error 4 Name 'fi' is not declared. C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\WindowsApplication1\WindowsApplication1\Form4.vb 27 34 WindowsApplication1
-
Jan 20th, 2010, 06:30 AM
#10
Re: list box
Try my ColorListBox control (link in signature). It allows you to display images. You won't be able to use data binding though; you'd have to loop through the filenames and add each item separately, like so
Code:
Dim di As New IO.DirectoryInfo("C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\trainersTool\images\plyo")
Dim name As String
Dim img As Image
For Each fi As FileInfo In di.GetFiles()
name = fi.Name
img = Image.FromFile(fi.FullName)
ColorListBox1.Items.Add(name, Color.Black, img)
Next
or something like that anyway.
-
Jan 20th, 2010, 06:41 AM
#11
Re: list box
copy the code exactly as it is with no extra spaces between lines + make sure the line continuation characters (_) are still in the code as in the posting
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 20th, 2010, 03:53 PM
#12
Thread Starter
Member
Re: list box
 Originally Posted by NickThissen
Try my ColorListBox control (link in signature). It allows you to display images. You won't be able to use data binding though; you'd have to loop through the filenames and add each item separately, like so
Code:
Dim di As New IO.DirectoryInfo("C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\trainersTool\images\plyo")
Dim name As String
Dim img As Image
For Each fi As FileInfo In di.GetFiles()
name = fi.Name
img = Image.FromFile(fi.FullName)
ColorListBox1.Items.Add(name, Color.Black, img)
Next
or something like that anyway.
erro on cololistbox1 not declaired?
-
Jan 20th, 2010, 03:58 PM
#13
Re: list box
Read the first sentence again. I am referring to a control I made. I posted the source for that control on this forum, but you'll still have to get it first.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|