Sign in to follow this  

[.net] Winforms design Issue

This topic is 3341 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
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

This topic is 3341 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this