PC Review


Reply
Thread Tools Rate Thread

Can this forloop be rewritten using foreach instead

 
 
Tony Johansson
Guest
Posts: n/a
 
      13th May 2009
Hello!
I have this method below that use a for loop to remove a DataRow from a
DataTable.
I have a DataGridView that is named dgvStock
I have a DataTable that is named _dataTable

I just wonder if it's possible to remove the for loop and
use a foreach loop insted but it might be problem because of the index into
dgvStock.

private void DeleteRedRow()
{
//Loop through all DataRow in the DataTable
for(int i = 0; i < _dataTable.Rows.Count; i++)
{
if (dgvStock.Rows[i].DefaultCellStyle.BackColor ==
System.Drawing.Color.Red)
{
_dataTable.Rows[i].AcceptChanges();
_dataTable.Rows[i].Delete();
}
}
}

//Tony


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can these lines be rewritten Tony Johansson Microsoft C# .NET 15 31st May 2010 09:17 AM
Can this forloop be rewritten using foreach instead Tony Johansson Microsoft C# .NET 12 13th May 2009 05:41 PM
TextBox/ForLoop Help Claude Grecea Microsoft C# .NET 5 3rd May 2007 05:54 AM
Import Specific Cells in Excel File with forloop =?Utf-8?B?SDBNRUxZ?= Microsoft Access External Data 1 11th Feb 2006 05:04 PM
Rewritten question =?Utf-8?B?Um9iZXJ0TQ==?= Microsoft Access Queries 1 31st Mar 2005 11:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:20 PM.