Jump to content
  • Advertisement
Sign in to follow this  
EvilNando

[.net] Winforms design Issue

This topic is 3559 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!