Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
int rowskip = 1;
for (int i = rowskip; i <= dataGridView1.Rows.Count - 1; i++)
{
 Double firsttotal = Convert.ToDouble(dataGridView1.Rows[i - 1].Cells[4].Value);
 Double amount = Convert.ToDouble(dataGridView1.Rows[i].Cells[2].Value);
 Double sum = firsttotal + amount;
 dataGridView1.Rows[i].Cells[4].Value = sum.ToString();
}
Posted
Updated 6-Jan-13 8:25am
v3
Comments
OriginalGriff 4-Jan-13 9:43am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
What doesn't work?
What should it do that it isn't, or shouldn't it do that it is?
Use the "Improve question" widget to edit your question and provide better information.
zeshanazam 4-Jan-13 9:47am    
can u just tell me to skip selected row to make for loop work ?
shaikh-adil 4-Jan-13 12:19pm    
http://www.codeproject.com/Questions/521745/transferingplustheplustextplusfromplusdynamicallyp
can you help me sir please if you can

Not too sure, but looks like you are talking of something like:
C#
if(! DataGridView1.SelectedRows.Contains(dataGridView1.Rows[i]))
{
  // Do something
}
else
{
  // This row is selected one!
}

Refer: MSDN: DataGridView.SelectedRows Property [^]
 
Share this answer
 
You have mentioned to skip the selected row in a gridview you can try something like below
C#
int rowskip = 1;
for (int i = rowskip; i <= dataGridView1.Rows.Count - 1; i++)
{
 
 if( dataGridView1.Rows[i].Selected)
 {
   continue;// skip this row if its selected
 }

 Double firsttotal = Convert.ToDouble(dataGridView1.Rows[i - 1].Cells[4].Value);
 Double amount = Convert.ToDouble(dataGridView1.Rows[i].Cells[2].Value);
 Double sum = firsttotal + amount;
 dataGridView1.Rows[i].Cells[4].Value = sum.ToString();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900