4 Replies - 2649 Views - Last Post: 04 March 2011 - 08:19 AM Rate Topic: -----

#1 shytonak   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 31-October 10

add images to listview

Posted 03 March 2011 - 06:32 PM

i want to add images to listview i use this code but it's not correct.
DirectoryInfo dir = new DirectoryInfo(Environment.CurrentDirectory + "\\Data\\");
            string text = tabControl1.SelectedTab.Text.ToString();
            FileInfo[] filer = dir.GetFiles("*" + text + "*.jpg.fcfe");
            foreach (FileInfo f in filer)
            {
                listBox3.Items.Add(f);
            }
            int t = listBox3.Items.Count;
            for(int i = 0;i<t;i++)
            {
                string file = Path.GetFileNameWithoutExtension(Environment.CurrentDirectory + "\\Data\\" + listBox3.Items[i].ToString());
                string s = Environment.GetFolderPath(Environment.SpecialFolder.History) + file;
                if (System.IO.File.Exists(s) == true)
                {
                    ListViewItem item1 = new ListViewItem(file, i);
                    listView1.Items.Add(item1);
                    ImageList imageListLarge = new ImageList();
                    imageListLarge.Images.Add(Bitmap.FromFile(s));
                    imageListLarge.ImageSize = new Size(156, 156);
                    imageListLarge.ColorDepth = ColorDepth.Depth32Bit;
                    listView1.LargeImageList = imageListLarge;
                }
                else
                {
                    string inFile = Environment.CurrentDirectory + "\\Data\\" + file + ".fcfe";
                    int index = inFile.LastIndexOf(".fcfe");
                    CryptoProgressCallBack cb = new CryptoProgressCallBack(this.ProgressCallBackDecrypt);
                    CryptoHelp.DecryptFile(inFile, (Environment.GetFolderPath(Environment.SpecialFolder.History)) + file, "1366", cb);
                    ListViewItem item1 = new ListViewItem(file, i);
                    listView1.Items.Add(item1);
                    ImageList imageListLarge = new ImageList();
                    imageListLarge.Images.Add(Bitmap.FromFile(s));
                    imageListLarge.ImageSize = new Size(156, 156);
                    imageListLarge.ColorDepth = ColorDepth.Depth32Bit;
                    listView1.LargeImageList = imageListLarge;
                }
            } 


Is This A Good Question/Topic? 0
  • +

Replies To: add images to listview

#2 Sergio Tapia   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1258
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: add images to listview

Posted 03 March 2011 - 06:40 PM

You're looping, and in each iteration creating a brand spanking new ImageList. Is this intended? *wink wink*
Was This Post Helpful? 1
  • +
  • -

#3 shytonak   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 31-October 10

Re: add images to listview

Posted 04 March 2011 - 04:03 AM

i don't know where is problem but i see just one picture and other pictures don't show.
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6534
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: add images to listview

Posted 04 March 2011 - 05:08 AM

View Postshytonak, on 04 March 2011 - 05:03 AM, said:

i don't know where is problem but i see just one picture and other pictures don't show.


Sergio told you what the problem is... You are making a new ImageList every time your loop executes. Thus, look inside your loop for the term 'new ImageList'

If this is *your* code it shouldn't be a problem.
If this is someone else's code you copy/pasted and you can't follow it enough to find the problem after someone told you what it was and where to look then you need to back up in your education and work your way up to this.

This post has been edited by tlhIn`toq: 04 March 2011 - 05:32 AM

Was This Post Helpful? 1
  • +
  • -

#5 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12317
  • View blog
  • Posts: 45,417
  • Joined: 27-December 08

Re: add images to listview

Posted 04 March 2011 - 08:19 AM

I've removed the posts not relevant to this topic. In the future, please keep posts on topic. Thanks! :)
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1