listview box insanity

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chris52672
    New Member
    • Mar 2009
    • 26

    listview box insanity

    Ok I am stuck. What I want is to have the file in the listview
    box with an icon. I can not seem to get the icon to show.
    what am I doing wrong?
    Code:
    //Set to the front tab for now
    			tabControl1.SelectedTab = tabPage2;
    
    
    			//Focus on tab page 1 for now
    			
    			//this.tabControl1.TabPages[1].Select();
    			string[] CipherFiles = System.IO.Directory.GetFiles(@"C:\Cipher\CipherResult");
    			
    			//File Info for file we looked at
    			System.IO.FileInfo fi = new System.IO.FileInfo(CipherFiles[0]);
    			string FileName = fi.Name;
    			string FileSize = fi.Length.ToString();
    			string FileType = fi.Extension;
    			object FileTypeObj = fi.GetType().BaseType;
    			string FileFull = fi.FullName;
    			string DateModifiedStr = fi.CreationTime.ToString();
    
    			//Create an array on how the headers will look
    			string []FormatStr = new string[4]{FileName,FileSize,FileType,DateModifiedStr};
    			ListViewItem LVHeader = new ListViewItem(FormatStr);
    			listViewFileOut.Items.Add(LVHeader);
    			
    			
    			//this is to get th icon
    			IconHandler GetIcon = new IconHandler();
    
    			//this starts a new image list
    			ImageList imageListLarge = new ImageList();
    
    			//Lets do something like adding a bmp
    			imageListLarge.Images.Add(Bitmap.FromFile(@"C:\Cipher\CipherPic.bmp"));
    
    			//This pust in the image
    			listViewFileOut.LargeImageList = imageListLarge;
  • xenoix
    New Member
    • Mar 2009
    • 15

    #2
    What you want to be doing is creating a new ListViewItem and send the index argument to point at which image you want it to display. Below is an example of what I mean...


    Hope it's of some help.

    Code:
                        Item[0] = f.Name;
                        Item[1] = Convert.ToString(f.Length);
                        Item[2] = Convert.ToString(f.CreationTime);
    
                        // Run through the file extensions and dispaly appropriate icons
                        switch (f.Extension.ToLower())
                        {
                            case ".txt":
                                EXT = TXT;
                                break;
    
                            case ".rtf":
                            case ".doc":
                            case ".dot":
                                EXT = WORD;
                                break;
    
                            case ".pdf":
                                EXT = PDF;
                                break;
    
                            case ".ini":
                                EXT = CONFIG;
                                break;
    
                            case ".url":
                            case ".hta":
                            case ".html":
                            case ".lnk":
                                EXT = WEB;
                                break;
    
                            case ".exe":
                            case ".msi":
                                EXT = EXE;
                                break;
    
                            case ".zip":
                                EXT = ZIP;
                                break;
    
                            case ".jpg":
                            case ".jpeg":
                            case ".gif":
                            case ".png":
                            case ".bmp":
                                EXT = PIC;
                                break;
                            
                            case ".rdp":
                                EXT = RDP;
                                break;
    
                            default:
                                EXT = FILE;
                                break;
    
                        }
                        LVFiles.Items.Add(new ListViewItem(Item, EXT));

    Comment

    Working...