我想做循环工作并跳过选定的gridview行。帮助我。 Thanx提前 [英] i want to make for loop work and skip the selected row of gridview. help me with this. Thanx in advance

查看:62
本文介绍了我想做循环工作并跳过选定的gridview行。帮助我。 Thanx提前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();
}

推荐答案

不太确定,但看起来你说的是:

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



参考: MSDN:DataGridView.SelectedRows属性 [ ^ ]


您提到跳过gridview中的选定行,您可以尝试下面的内容

You have mentioned to skip the selected row in a gridview you can try something like below
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();
}


这篇关于我想做循环工作并跳过选定的gridview行。帮助我。 Thanx提前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆