Jump to content
  • Advertisement
Sign in to follow this  
Stormtrooper

[C#]Casting and Enumerators [FIXED]

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

EDIT: got it working, see second post. Ok, I have a custom control which displays a ToDo. I created a custom panel to hold/display the custom ToDo control. Back in the main code I keep a list of every ToDo. Now, in the custom panel control, whenever the user updates the ToDo via the interface, I want it to be updated in the list. The only way I can think to od this is to loop through each control, cast it as a ToDoItem control, get the ToDo property, then update the corresponding ToDo in the list. But how do I do this? The following code doesn't work, it doesn't like me casting the iterator.
[source="c#"]
        public void populateView(List<ToDo> todoList, ToDo.ToDoView view, String project)
        {
            // Update the list
            IEnumerator itr = this.Controls.GetEnumerator();
            while (itr.MoveNext())
            {
                todoList.ForEach(delegate(ToDo item)
                {
                    if (item.ID == (ToDo)itr.Current().todo.ID)
                    {
                        (ToDo)itr.Current().todo = item;
                    }
                });
            }

            flowLayoutPanel.Controls.Clear();
            todoList.ForEach(delegate(ToDo item)
            {
                if (item.View == ToDo.ToDoView.Project)
                {
                    if(item.Project == project)
                    {
                        flowLayoutPanel.Controls.Add(new ToDoItem(item));
                       
                    }
                }
            });
        }

Share this post


Link to post
Share on other sites
Advertisement
I tried this loop, but it only broke stuff

[source="c#"]
this.todoList.ForEach(delegate(ToDo item)
{
todoList.ForEach(delegate(ToDo item2)
{
if (item.ID == item2.ID)
{
item = item2;
}
});
});/source]

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!