Click here to Skip to main content
13,148,573 members (52,889 online)
Rate this:
Please Sign up or sign in to vote.
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?)

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.
  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];
Posted 27-Dec-11 5:20am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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
SAKryukov 27-Dec-11 12:07pm
It could be useful, my 5, but the root of the problem is general approach.
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.
Mika Wendelius 28-Dec-11 17:09pm
Very good links!
Espen Harlinn 28-Dec-11 17:29pm
Thanks Mika!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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[^]).

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.

Espen Harlinn 27-Dec-11 12:05pm
Good points :)
SAKryukov 27-Dec-11 12:06pm
Thank you, Espen.
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?
SAKryukov 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!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170924.2 | Last Updated 4 Jan 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100