I used to fill a listview with dataset that is set to details view. Now, I need to fill the listview with images and by that I believed that I'd set the view to large icons. How to do this?

this is how I feel the listview

foreach (DataRow dr in ds.Tables["tblEventType"].Rows)
                ListViewItem lvi = new ListViewItem(dr["eventName"].ToString());


Recommended Answers

All 3 Replies

For having images in the listView (on in some other control), best way is to use an ImageList. You put images inside, and from there show images in listView. For example, how to get images form a disc, send then to imageList and then to listView:

//for better accurecy you can you an OpenFileDialog class, in which you can set a filter to show only images (png, img, bmp...)
            DirectoryInfo dir = new DirectoryInfo(@"C:\MyPictures");
            foreach (FileInfo file in dir.GetFiles())
                    MessageBox.Show("This is not an image file");
            this.listView1.View = View.LargeIcon;
            this.imageList1.ImageSize = new Size(32, 32);
            this.listView1.LargeImageList = this.imageList1;
            //this.listView1.View = View.SmallIcon;
            //this.listView1.SmallImageList = this.imageList1;
            for (int j = 0; j < this.imageList1.Images.Count; j++)
                ListViewItem item = new ListViewItem();
                item.ImageIndex = j;

Hope it give you an idea,

commented: thanks +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.