Search code examples
c#winformslistview

How to write text in Listview


This is my code to write text with a image in list view.

            var imageList = new ImageList();
            Image image = Image.FromFile("ABC.png");
            imageList.Images.Add("ABC", image);
            listView1.LargeImageList = imageList;
            var listViewItem = listView1.Items.Add("text with image");
            listViewItem.ImageKey = "ABC";

The issue I am facing is the text and the image should come in one row but currently they are coming in multiple rows.

enter image description here


Solution

  • Thanks to @Klaus Gütter I was able to solve this.

    I changed the view from LargeIcons to SmallIcons.

    Also did change this line in the code.

     listView1.SmallImageList = imageList;