473,387 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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?
Expand|Select|Wrap|Line Numbers
  1. //Set to the front tab for now
  2.             tabControl1.SelectedTab = tabPage2;
  3.  
  4.  
  5.             //Focus on tab page 1 for now
  6.  
  7.             //this.tabControl1.TabPages[1].Select();
  8.             string[] CipherFiles = System.IO.Directory.GetFiles(@"C:\Cipher\CipherResult");
  9.  
  10.             //File Info for file we looked at
  11.             System.IO.FileInfo fi = new System.IO.FileInfo(CipherFiles[0]);
  12.             string FileName = fi.Name;
  13.             string FileSize = fi.Length.ToString();
  14.             string FileType = fi.Extension;
  15.             object FileTypeObj = fi.GetType().BaseType;
  16.             string FileFull = fi.FullName;
  17.             string DateModifiedStr = fi.CreationTime.ToString();
  18.  
  19.             //Create an array on how the headers will look
  20.             string []FormatStr = new string[4]{FileName,FileSize,FileType,DateModifiedStr};
  21.             ListViewItem LVHeader = new ListViewItem(FormatStr);
  22.             listViewFileOut.Items.Add(LVHeader);
  23.  
  24.  
  25.             //this is to get th icon
  26.             IconHandler GetIcon = new IconHandler();
  27.  
  28.             //this starts a new image list
  29.             ImageList imageListLarge = new ImageList();
  30.  
  31.             //Lets do something like adding a bmp
  32.             imageListLarge.Images.Add(Bitmap.FromFile(@"C:\Cipher\CipherPic.bmp"));
  33.  
  34.             //This pust in the image
  35.             listViewFileOut.LargeImageList = imageListLarge;
Mar 31 '09 #1
1 1615
xenoix
15
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.

Expand|Select|Wrap|Line Numbers
  1.                     Item[0] = f.Name;
  2.                     Item[1] = Convert.ToString(f.Length);
  3.                     Item[2] = Convert.ToString(f.CreationTime);
  4.  
  5.                     // Run through the file extensions and dispaly appropriate icons
  6.                     switch (f.Extension.ToLower())
  7.                     {
  8.                         case ".txt":
  9.                             EXT = TXT;
  10.                             break;
  11.  
  12.                         case ".rtf":
  13.                         case ".doc":
  14.                         case ".dot":
  15.                             EXT = WORD;
  16.                             break;
  17.  
  18.                         case ".pdf":
  19.                             EXT = PDF;
  20.                             break;
  21.  
  22.                         case ".ini":
  23.                             EXT = CONFIG;
  24.                             break;
  25.  
  26.                         case ".url":
  27.                         case ".hta":
  28.                         case ".html":
  29.                         case ".lnk":
  30.                             EXT = WEB;
  31.                             break;
  32.  
  33.                         case ".exe":
  34.                         case ".msi":
  35.                             EXT = EXE;
  36.                             break;
  37.  
  38.                         case ".zip":
  39.                             EXT = ZIP;
  40.                             break;
  41.  
  42.                         case ".jpg":
  43.                         case ".jpeg":
  44.                         case ".gif":
  45.                         case ".png":
  46.                         case ".bmp":
  47.                             EXT = PIC;
  48.                             break;
  49.  
  50.                         case ".rdp":
  51.                             EXT = RDP;
  52.                             break;
  53.  
  54.                         default:
  55.                             EXT = FILE;
  56.                             break;
  57.  
  58.                     }
  59.                     LVFiles.Items.Add(new ListViewItem(Item, EXT));
  60.  
Apr 1 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Anushya | last post by:
Hi I am using Listview and inherited listview control overriding WndProc & PreProcessMessage in ListView. I need this to customize listview to display only the page the user scrolls to. Since i...
0
by: Anushya | last post by:
Hi I am using Listview and inherited listview control overriding WndProc & PreProcessMessage in ListView. I need this to customize listview to display only the page the user scrolls to. Since i...
6
by: VM | last post by:
How can I fill up a listview with text file contents? My listview has two columns and the first column fills up with a while loop: while (myString != null) { myString = sr.Readline();...
0
by: keith | last post by:
In a ListView control (two columns), I added a few ListView items. ListView listview=new ListView(); listview.Parent=this; listview.View=View.Details; listview.Columns.Add...
7
by: Dave Y | last post by:
I am a newbie to C# and am having trouble trying to override a ListView property method. I have created a new class derived from the Forms.Listview and I cannot figure out the syntax to override...
7
by: BobAchgill | last post by:
I am trying to decide which of these controls to use to implement letting my user select a full row from MyList. The MyList has several columns which would be nice to sort by at run time. The...
2
by: Ben H | last post by:
Hello all I'm using a listview in my app but I want to scroll the listview programatically as I hate the look of the standard scrollbar. So, the listview is scrolled programatically using...
2
by: Peter | last post by:
Hi, I have a problem with Listview using checkboxes. If i check items by code BEFORE the form is shown the Listview.Items are confused during the ItemChecked Event !!! After showing the...
4
by: Brian Gaze | last post by:
I have created a ListView control and have bound this to a datasource. Within the ItemTemplate of the ListView I have added another ListViewControl which is databound in the code behind. The idea...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.