Click here to Skip to main content
13,258,878 members (47,961 online)
Rate this:
Please Sign up or sign in to vote.
See more:

My First Post! Be easy on me :P

I have a Small SQL CE Database that consists of three tables. Each Table gets filled into a seperate DataGridView, once this is completed a simple foreach loop iterates through an imagelist(s). One per DataGridView and matches the Primary Key to the Index of the ImageList. This populates the appropriate columns with the correct image. There is not much data here: 200 Rows, 10 columns per Table.

Right now i'm not liking using the index of the image stored in the imagelist because if I remove an entry from the table my primary key does not match the appropriate image and display the incorrect one. Whats the best way to simplify this? I'm trying to achive a simple way to update and remove data later on and have the appropriate image correspond with what is in the table. I have experimented with adding a new column to the table with a file name and then loading the images based on the filename in the imagelist which seems to work fine. Just looking for ideas! Any help is appreciated. Thanks
Posted 16-Apr-12 8:28am
Nelek 16-Apr-12 17:16pm
To be your first question you decribed it quite good. Don't be afraid, there is no problem on being new. :)

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

My first thought is: Where do the images come from that build the image list? Something must have built the image list from somewhere ... was that somewhere a persistent storage of some kind (file system? database?).

If so, then that persistent storage will have some unique identifier for the images that you can use instead of the image list.

Lets assume, however, that the image list is built dynamically and there's no persistent storage (yet).

In .Net images are reference types - which means you can 'store' them in multiple memory structures with minimal memory overhead (just the size of the reference). So... As you accumulate images, add them first to a collection (List<Image>, perhaps) and second add them to the ImageList. Also, build a dictionary that correlates their position in the image list to their position in the 'behind the scenes' list. (Actually, if you do it right, you may find you don't need both the dictionary and the list; I've not gone far enough down the design road to know).

Now, (a) you store in your data grids the index (or whatever) of the images in the list, and (b) when you remove images from the ImageList, you do not remove them from the list... so references to that list never get stale until you're ready to clear the whole world and start over.

Painstream 17-Apr-12 12:23pm
Thanks for the reply Chris, you've pointed me in the correct direction. I was able to use unique identifers.

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 |
Web01 | 2.8.171114.1 | Last Updated 16 Apr 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