Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my first time to post and I'm non-native speaker of English, so no flames about my bad English please.

I'm using visual studio 11 and making a windows form application like a pdf file management software. Now, I can add pdf files to listveiw and save the top page of pdf files in imagelist as a thumbnail.

But I have no idea to match images in imagelist and items in listview.

When adding items in listview, I matched the number of items and index of imagelist and I seemed to make the function, but if I remove items, the corresponding image should be removed but I don't know how to do this. (Is this best way?)

C#
int VolNum = listView1.Items.Count; //counting items in listview1
ListViewItem itm = listView1.Items.Add(fileName, VolNum); //match items(fileName) and images in imagelist


Moreover, I export items in listview to CSV, and load the CSV file on start-up. Please tell me how to match items in listview and images in imagelist.
I use this code to read CSV.
C#
StreamReader srInf = new StreamReader(@"C:\data.csv");

  String filedata;

  while ((filedata = srInf.ReadLine()) != null)
  {

      string[] csvdata = filedata.Split(',');


      ListViewItem Listdata = new ListViewItem();
      Listdata.Text = csvdata[0];
      Listdata.SubItems.Add(csvdata[1]);
      Listdata.SubItems.Add(csvdata[2]);
      listView1.Items.Add(Listdata);
  }

  srInf.Close();
Posted

Have a look at ObjectListView[^]
Here is an article A Much Easier to Use ListView[^].

If you really want to use the standard listview, have a look at custom painting[^].

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 27-Dec-11 12:07pm    
It could be useful, my 5, but the root of the problem is general approach.
--SA
Espen Harlinn 27-Dec-11 12:09pm    
Thank you, Sergey!
MillionX30 27-Dec-11 12:36pm    
Thank you for your comment! Those links must be helpful to me.
Wendelius 28-Dec-11 17:09pm    
Very good links!
Espen Harlinn 28-Dec-11 17:29pm    
Thanks Mika!
You English is fine; I wish other members could post their question in such a clear language free from ugly spelling mistakes. However, your problem looks artificial. You put some unmatched data in controls in first place and later wants to match items. Why?

You should do the following: you need to separate your data layer from UI. When you want to find anything in data, an actual data element of some relationship, find it in data, not in the UI control.

As to your problems, you can do one of the following: 1) do not store images and file names separate, work with a list of structures containing both; 2) create a dictionary, such as System.Collection.Generic.Dictionary<string, Image> indexed by the file names (say, lo-case them before using as a key); that will give you a fast O(1) search of data by the file name (if you don't know "Big O" notation, read http://en.wikipedia.org/wiki/Big_O_notation[^]).

After you got a proper data model, think about data binding to your UI. In a simplest but most flexible case, it could be as simple as two method: population of UI from data and update data from UI, but chances are, you might need more complex UI behavior, but nevertheless, do it using the data model, not just UI or data in UI. On these grounds, also critically re-think you UI design. I don't know your detail, but if you change your approach, do some development but face with problems, ask your further questions. Most likely I would be able to help, other experts will probably help, too.

—SA
 
Share this answer
 
Comments
Espen Harlinn 27-Dec-11 12:05pm    
Good points :)
Sergey Alexandrovich Kryukov 27-Dec-11 12:06pm    
Thank you, Espen.
--SA
MillionX30 27-Dec-11 12:48pm    
It is kind of you to give me such advice so quickly. I couldn't get any (kind) advice in my country's community.
I'll try to do it as you say.
MillionX30 1-Jan-12 5:01am    
I want to create an application such as iTunes and Windows Media Player. I want to make my application UI stylish so I want to use ObjectListView in the future, but at first I have to make fundamental function of just storing the file name, path, thumbnail etc.

According to your advice, I decided to use SQlite as a database to save text and also image.
Now I can store text(file name, path, etc) into SQlite database other than image. So my next step will be to store image(thumbnail) simultaneously when file is added to the application.

After this, when I want to match items and thumbnails, what shall I do?
Maybe, each item and thumbnail will be stored in the same row. Is image should be extracted to imagelist and then be matched with proper item?
Sergey Alexandrovich Kryukov 4-Jan-12 13:12pm    
You have some options. The idea of storing them in the same row is right, but you can store either a whole image as a blob or a file names, or a file name for a big image, a blob for a thumbnail.

Good luck, best wishes in New Year!
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900