Click here to Skip to main content
16,004,678 members
Home / Discussions / C#
   

C#

 
GeneralRe: TextBox Event Not Triggering Pin
Thomas Stockwell11-Jan-08 14:51
professionalThomas Stockwell11-Jan-08 14:51 
Questionnamespace 'Windows' does not exist Pin
Steve Harp11-Jan-08 6:03
Steve Harp11-Jan-08 6:03 
GeneralRe: namespace 'Windows' does not exist Pin
Luc Pattyn11-Jan-08 6:08
sitebuilderLuc Pattyn11-Jan-08 6:08 
AnswerRe: namespace 'Windows' does not exist Pin
Steve Harp11-Jan-08 6:29
Steve Harp11-Jan-08 6:29 
GeneralRe: namespace 'Windows' does not exist Pin
Luc Pattyn11-Jan-08 6:34
sitebuilderLuc Pattyn11-Jan-08 6:34 
GeneralRe: namespace 'Windows' does not exist Pin
Steve Harp11-Jan-08 7:00
Steve Harp11-Jan-08 7:00 
GeneralProblem to DataTable.Rows.Remove(DataRow row) method. Pin
hdv21211-Jan-08 4:02
hdv21211-Jan-08 4:02 
GeneralRe: Problem to DataTable.Rows.Remove(DataRow row) method. Pin
Dave Kreskowiak11-Jan-08 4:34
mveDave Kreskowiak11-Jan-08 4:34 
hdv212 wrote:
foreach (DataRow row in dtDbUsers.Rows)
{
if (row["LoginName"].ToString() == "##MS_AgentSigningCertificate##")
dtDbUsers.Rows.Remove(row); // error in this line
}


This means that you cannot add or remove items from the collection while you're enumerating it. foreach creates an Enumerator over the collection automatically.

You can use a normal for statement and index through the collection to do this. I would highly recommend that you start at the end of the collection and work your way to index 0. This will prevent you from deleting an item and skipping the next item in the collection. This is because when you remove an item at one index, say number 5, the items in indexs 6 through whatever all move down one. So item 6 is now at item 5. When your get to the bottom of the loop and the index variable incerements, you're no longer looking at item 5, but instead you're looking at the new item 6. The new item 5 gets skipped over.



A guide to posting questions on CodeProject[^]



Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007




GeneralRe: Problem to DataTable.Rows.Remove(DataRow row) method. Pin
hdv21211-Jan-08 5:38
hdv21211-Jan-08 5:38 
GeneralIdentify record in Global Catalog Pin
robot_rock11-Jan-08 3:33
robot_rock11-Jan-08 3:33 
GeneralRe: Identify record in GC Pin
Justin Perez11-Jan-08 4:15
Justin Perez11-Jan-08 4:15 
GeneralRe: Identify record in GC Pin
robot_rock11-Jan-08 4:28
robot_rock11-Jan-08 4:28 
GeneralRe: Identify record in GC Pin
Dave Kreskowiak11-Jan-08 4:30
mveDave Kreskowiak11-Jan-08 4:30 
GeneralRe: Identify record in GC Pin
robot_rock11-Jan-08 4:44
robot_rock11-Jan-08 4:44 
GeneralRe: Identify record in GC Pin
Dave Kreskowiak11-Jan-08 6:20
mveDave Kreskowiak11-Jan-08 6:20 
GeneralRe: Identify record in GC Pin
robot_rock11-Jan-08 6:55
robot_rock11-Jan-08 6:55 
GeneralRe: Identify record in GC Pin
Dave Kreskowiak11-Jan-08 12:24
mveDave Kreskowiak11-Jan-08 12:24 
GeneralRe: Identify record in GC Pin
robot_rock11-Jan-08 12:49
robot_rock11-Jan-08 12:49 
GeneralRe: Identify record in GC Pin
robot_rock11-Jan-08 15:12
robot_rock11-Jan-08 15:12 
QuestionHow to Use C# realize the graphic website map? [modified] Pin
Member 472830111-Jan-08 1:29
Member 472830111-Jan-08 1:29 
AnswerRe: How to realizing the website mapeer? PinPopular
Pete O'Hanlon11-Jan-08 1:36
mvePete O'Hanlon11-Jan-08 1:36 
GeneralRe: How to realizing the website mapeer? Pin
Member 472830111-Jan-08 5:02
Member 472830111-Jan-08 5:02 
GeneralRe: How to realizing the website mapeer? Pin
led mike11-Jan-08 5:03
led mike11-Jan-08 5:03 
GeneralRe: How to realizing the website mapeer? Pin
Member 472830111-Jan-08 5:15
Member 472830111-Jan-08 5:15 
GeneralRe: How to realizing the website mapeer? Pin
Pete O'Hanlon11-Jan-08 23:04
mvePete O'Hanlon11-Jan-08 23:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.