如何在datagridview中的行的文本框中显示结果?
问题描述:
我想创建一个小程序来创建一个将两个数字相加的算术运算符。如何在datagridview中的行的文本框中显示结果?
当我双击我的datagridview中的一个单元格,那么我的外部文本框将显示此行的结果。
例如:
1 3
3 5
2 8
我也创建一个类为我的程序,类名是CAC,并在它的方法是
public int CacAB()
{
int result= a + b;
return result;
}
的第一行的结果应该是4 ,第二行应该是8,第三行应该是10.
我的文本框的名字就是textBox1,我的datagridview的名字就是datagridview1,怎么做到的呢?非常感谢。
我知道我需要创建一个方法,如:“dataGridView1_CellDoubleClick”到目前为止。
答
所以我觉得可能是你想要实现这个
private void DataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
int firstValue = Convert.ToInt32(DataGridView1.Rows(e.RowIndex).Cells("Column1").Value.ToString());
int secondValue = Convert.ToInt32(DataGridView1.Rows(e.RowIndex).Cells("Column2").Value.ToString());
textBox.Text = (firstValue + secondValue).ToString();
}
+1
你需要一个ToString()来添加,但是应该可以。 – 2013-03-24 22:52:25
第二个结果我得到了,而搜索'datagridview的celldoubleclick'是[本条](http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/21f212d7-31b3-4ef1-a177-f89614facb33 /)...其中的第一个答案显示了如何访问DataGridView的单元格。访问它们并添加它们。 – 2013-03-24 22:51:16