[.net] Winforms design Issue

Started by
2 comments, last by DaWanderer 15 years, 6 months ago
Hi all, Im making an editor for my game. Right now I'm in the process of designing and creating a custom control which is function is to store and display "Image Banks" by definition an Image Bank is just a structure that holds an Id a file path pointing to a valid image file and an Image type member struct ImageBank { Int32 id String file_name Image image }; the best looking solution that Ive found for displaying a collection of these datatypes is the list view, sadly the ListView does not accept a custom datatype as an item. So Ive made a workaround where I have a List<ImageBank> that holds all entries and a function UpdateListView() that parses the List<ImageBank> and updates the ListView accordingly. I would like to hear some input about this because Im a little worried of having 2 entities for holding the same data (the list view and the List<ImageBank>) a quick preview Photobucket [This is a post a just did in the gen. prog. forums I'm moving it here because it makes more sense, I deleted the orginial post's content]
Advertisement
Sorry if I'm missing the point, but why use this instead of an ImageList?

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

The requierments of this control are a little bit more complex than the functionality an imagelist can provide
Could you maybe assign each ImageBank object to the Tag property of each ListViewItem? Then your UpdateListView() method walk through the ListView.Items collection, cast each Tag property, and set the ListViewItem.SubItems appropriately.

Something like this:

public void AddBank(ImageBank bank){   // Set up item initially   ListViewItem newItem = new ListViewItem(bank.id.ToString());   newItem.Tag = bank;   // ...   listView1.Items.Add(newItem);}public void UpdateListView(){   foreach (ListViewItem item in listView1.Items)   {      ImageBank bank = (ImageBank)item.Tag;      // Update item...   }}


It's not the perfect solution, but you at least avoid having a duplicate list. If you were to use a class instead of a struct, then the "duplicate" list would really just be duplicate object references.

This topic is closed to new replies.

Advertisement