I am working on windows .net (Language c#) appliation where i have displayed summary of data in data grid (Language c#) of various text boxes
i want to change the value of cell and any operation related to it must be trigered
for example:
In a datagrid1
cell 1 takes 3
cell 2 takes 3
and
cell 3 sums 3+3=6 (in data grid view)
cell 4 minus 3-3=0
cel 5 multiply 3*3=9
cell 6 divide 3/3=1
| number1 | number2 | sum | minus | multiply | divide |
| 3 | 3 | 6 | 0 | 9 | 1 |
| edit above cell | edit above cell |
if i change the values of cell 1 or cell 3 the same must be reflected in the cell 3,4,5,6
I hope this is clear to you and i thank you in reviewing my post and answering me back
Shen HengbinPosted Jul 21, 2012, 6:12 AM
raj kiranPosted Jul 20, 2012, 11:31 AM
{
if (e.RowIndex ==-1 || e.ColumnIndex > 1) return;
dgridEstimationII.CellValueChanged -= new DataGridViewCellEventHandler(dgridEstimationII_CellValueChanged);
var a = 0;
var b = 0;
var c = 0;
int.TryParse(dgridEstimationII.Rows[e.RowIndex].Cells[2].Value + "", out a);
int.TryParse(dgridEstimationII.Rows[e.RowIndex].Cells[3].Value + "", out b);
int.TryParse(dgridEstimationII.Rows[e.RowIndex].Cells[4].Value + "", out c);
dgridEstimationII.Rows[e.RowIndex].Cells[5].Value = a * b;
dgridEstimationII.Rows[e.RowIndex].Cells[6].Value = a * c;
var d = 0;
var f = 0;
int.TryParse(dgridEstimationII.Rows[e.RowIndex].Cells[5].Value + "", out d);
int.TryParse(dgridEstimationII.Rows[e.RowIndex].Cells[6].Value + "", out f);
dgridEstimationII.Rows[e.RowIndex].Cells[7].Value = d + f;
dgridEstimationII.CellValueChanged += new DataGridViewCellEventHandler(dgridEstimationII_CellValueChanged);
}
i tried this out but problem is only when i change the cell (0 0) there are changes updating
where i dont need to change (0 0)
i think there is some thing with
if (e.RowIndex ==-1 || e.ColumnIndex > 1) return;
can you please help me with this
raj kiranPosted Jul 20, 2012, 8:26 AM
then the r/w.cost =weight cell * R/M rate
fab.cost=weight cell * Fab rate
total cost = r/wcost+fab.cost
can you please send me the code for this the above code by you was fine but i tried to change but could not make it right
Thank you in advance
Shen HengbinPosted Jul 20, 2012, 4:52 AM
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1 || e.ColumnIndex > 1) return;
dataGridView1.CellValueChanged -=new DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
var a = 0;
var b = 0;
int.TryParse(dataGridView1.Rows[e.RowIndex].Cells[0].Value + "", out a);
int.TryParse(dataGridView1.Rows[e.RowIndex].Cells[1].Value + "", out b);
dataGridView1.Rows[e.RowIndex].Cells[2].Value = a + b;
dataGridView1.Rows[e.RowIndex].Cells[3].Value = a - b;
dataGridView1.Rows[e.RowIndex].Cells[4].Value = a * b;
dataGridView1.Rows[e.RowIndex].Cells[5].Value = b == 0 ? 0 : a / b;
dataGridView1.CellValueChanged += new DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
}