a question on listviews

keko2004

Active member
Joined
Feb 13, 2006
Messages
39
Location
Middle Village, NY
Programming Experience
1-3
heys guys, im not writing this in vb.net, im using c#, i wasnt in the mood to sign up for a c# forum so maybe you can just tell me how to do it in vb and ill translate it into c#. im using a list view to display file names and file paths. now i want to show the icon of the file when the user inserts the file to the listview, how can i go about doing this. i tried using a imagelist but i never used one before, so i know im doin something wrong cause when the program loads, it shows the same icon image for all files, and the icon image happens to be the one for VSC# that i added to the image list. can anyone help?

thanks
 
umm i had to use this:

listView1.Items[0].ImageIndex = 3;

but when a user adds a file, how do i obtain the icon along with the file name(i know how to retrieve the file name);
 
Hello Keko,
Yes it is a way how you can add the image to the listview too but you need a different approach. Maybe something like this:

VB.NET:
[SIZE=2][COLOR=#0000ff]private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2] button1_Click([/SIZE][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][SIZE=2] sender, [/SIZE][SIZE=2][COLOR=#008080]EventArgs[/COLOR][/SIZE][SIZE=2] e)
{
[/SIZE][SIZE=2][COLOR=#0000ff] if[/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff]this[/COLOR][/SIZE][SIZE=2].openFileDialog1.ShowDialog() == [/SIZE][SIZE=2][COLOR=#008080]DialogResult[/COLOR][/SIZE][SIZE=2].OK)
   {
[/SIZE][SIZE=2][COLOR=#0000ff]     this[/COLOR][/SIZE][SIZE=2].listView1.Items.Add(openFileDialog1.FileName, 2);
    }
}
[/SIZE]

Below is the demo project so you can take a look ... Regards ;)
 

Attachments

  • CSharpListView.zip
    39.2 KB · Views: 26
keko2004 said:
heys guys, im not writing this in vb.net, im using c#, i wasnt in the mood to sign up for a c# forum so maybe you can just tell me how to do it in vb and ill translate it into c#. im using a list view to display file names and file paths. now i want to show the icon of the file when the user inserts the file to the listview, how can i go about doing this. i tried using a imagelist but i never used one before, so i know im doin something wrong cause when the program loads, it shows the same icon image for all files, and the icon image happens to be the one for VSC# that i added to the image list. can anyone help?
thanks

in vb i make use of a ListViewItem..
jst make sure you have associated an imagelist to a listview...

dim lv as new ListViewItem

lv.ImageIndex=0
lv.Text="You Item"

listview.Items.Add(lv)
 
Back
Top