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)
{
开发者_如何学Python 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();
}
}
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);
精彩评论