views:

99

answers:

1

Hello Again,

I have looked through the listview controls and wasnt able to find how the label for each item is defined. When I load an image into the listview, I see the full path of the image under the image. What Im looking to do is replace the text with something more descriptive of the image itself, and not the path where it is located.

If someone can point me in the right direction, I would be thankful.

Edit to be more descriptive: What I have is a program that automatically loads images when it starts, the images are loaded into a listview and shown in the Large Icon view. So when they are loaded, the icon displays, and the text(label) underneath shows the path of the image. If I can get it to display just the filename, that would be awesome. All this is done programmatically.

private void Form1_Load(object sender, EventArgs e)
    {
        listView1.LargeImageList = imageList1;
        var files = System.IO.Directory.GetFiles(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\icons");

        foreach (var item in files)
        {
            addImage(item);
        }

    }

    private void addImage(string imageToLoad)
    {
        if (imageToLoad != "")
        {
            imageList1.Images.Add(Image.FromFile(imageToLoad));
            listView1.BeginUpdate();
            listView1.Items.Add(imageToLoad, imageList1.Images.Count - 1);
            listView1.EndUpdate();

        }
    }
+2  A: 

I believe it's just the Text Property of ListViewItem.

Edit:

So just change this line:

listView1.Items.Add(imageToLoad, imageList1.Images.Count - 1);

to

listView1.Items.Add(System.IO.Path.GetFileName(imageToLoad), imageList1.Images.Count - 1);
Steve Danner
Right, but 'Some Custom Text' will be applied to all the icons that are imported. Im looking for something that makes each describe the image, even if it is just one word. And manually naming each one on import would be a long process, and would need to be done each time the program starts, checking for new images. I understand how to add text to a icon, as described above by your example, but how would I go about making that text the filename instead.
Rekar
I modified the line to display just the filename without the full path for every image you try to load. Is that what you're after?
Steve Danner
Wow, thank you for your help.
Rekar