Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 1st, 2007, 4:49 PM   #1
BlazingWolf
Hobbyist Programmer
 
Join Date: Sep 2004
Posts: 207
Rep Power: 4 BlazingWolf is on a distinguished road
Flow Control Issue

Ok, this one just doesn't make any sense to me. In the code below if I remove the comments around the nested loop the if statement below it doesn't execute, but if that loop is commented out it executes perfectly.

Why?

  
foreach (TreeViewItem tviGrp in tvcBuddyList)
{
      /*--------------------------
      //Remove from any groups the user may be in
       foreach (TreeViewItem tviUser in tviGrp.Items)
        {
              if (tviUser.Name == user.Name)
              {
                 tviGrp.Items.Remove(tviUser);
               }
        }
        ----------------------------*/
        //Add the user to the offline group
        if (tviGrp.Name == "Offline")
        {
           TreeViewItem tviUser = new TreeViewItem();
           tviUser.Header = user.Name;
           tviUser.Name = user.Name;
           tviGrp.Items.Add(tviUser);
         }
}
__________________
_______________________________
BlazingWolf
BlazingWolf is offline   Reply With Quote
Old Feb 1st, 2007, 5:00 PM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Removing items from a list you're in the middle enumerating over is usually not a good idea. That may be where the problem stems from.
Arevos is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding standards without control? martinig Other Programming Languages 1 Dec 4th, 2006 7:04 AM
questions on windows sendMessage and RichEdit control nomer C++ 1 Mar 3rd, 2006 2:51 AM
IR control firehawk Assembly 0 Feb 25th, 2006 8:34 AM
C programing control of the Serial Port. Light C++ 5 Feb 24th, 2005 2:14 PM
Show web user control hidden see07 C# 1 Feb 2nd, 2005 10:35 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:39 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC