Reputation: 553
I want to create a small program to create an arithmetic operator that adds two numbers together.
when I double click a cell in my datagridview, then my textbox outside will display the result of this row.
for example:
1 3
3 5
2 8
I also create a class for my program, the class's name is Cac, and the method in it is
public int CacAB()
{
int result= a + b;
return result;
}
the result for first row should be 4, second row should be 8 and the third row should be 10.
my textbox's name is just textBox1 and my datagridview's name is just datagridview1, how to make it? thanks very much.
I know I need create a method like:"dataGridView1_CellDoubleClick" so far.
Upvotes: 0
Views: 1218
Reputation: 40970
So I think may be you want to achieve this
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();
}
Upvotes: 1