Click here to Skip to main content
15,909,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

Please give some suggestions for add image with text nth column of Listview in Windows application.

I am able to add image text at column 1 only, not able to add at second or third column where index need to pass for this image with text.



Awaiting for your replies.

Regard's
Surendra

What I have tried:

ImageList Imagelist = new ImageList();

DirectoryInfo dir = new DirectoryInfo(@"c:\pic");
foreach (FileInfo file in dir.GetFiles())
{
    try
    {
        Imagelist.Images.Add(Image.FromFile(file.FullName));
    }
    catch
    {
        Console.WriteLine("This is not an image file");
    }
}


listView1.View = View.Details;
Imagelist.ImageSize = new Size(20, 20);
listView1.SmallImageList = Imagelist;
int count = dir.GetFiles().Count();


for (int i = 0; i < count; i++)
{

    listView1.Items.Add(new ListViewItem {ImageIndex = i, Text = "Image" + i });
}
Posted
Comments
Richard MacCutchan 12-May-17 6:47am    
It is because that is how a ListView works. If you want images in other columns you would need to write your own class to do all the work.

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