Hi .. I am new at c# . I am making an invoice generator . In it i am using dataGridView. Its a very new to me. GridView has 4 columns. Item, Quantity, PriceperItem and total. Values in 'item' clumn come from database. and user enters values of 'quantity' and 'priceperitem'. the total value should be automatically generted by calculating quantity*priceperitem when user click on 'yotal' column's cell. I have searched on google alottt but still wondering. I have done something like this but of no value. Kindly help me. Thanks in advance.
public void newFunc()
{
string val;
string val1;
int col = this.dataGridView1.CurrentCell.ColumnIndex;
if (col == 3)
{
val = this.dataGridView1.Columns[1].ToString();
val1 = this.dataGridView1.Columns[2].ToString();
int v = int.Parse(val);
int v1 = int.Parse(val1);
int v2 = v * v1;
this.dataGridView1.CurrentCell.Value = v2;
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
newFunc();
}
Hemant SrivastavaPosted Dec 26, 2014, 3:04 PM
Hi ABC DEF,
Try this:
public void newFunc(int row, int col)
{
string val, val1;
val = this.dataGridView1.Rows[row].Cells[1].Value.ToString();
val1 = this.dataGridView1.Rows[row].Cells[2].Value.ToString();
int v = int.Parse(val);
int v1 = int.Parse(val1);
int v2 = v * v1;
this.dataGridView1.Rows[row].Cells[col].Value = v2;
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int col = this.dataGridView1.CurrentCell.ColumnIndex;
int row = this.dataGridView1.CurrentCell.RowIndex;
if (col == 3)
{
newFunc(row, col);
}
}
Joginder BangerPosted Dec 26, 2014, 11:57 AM
First of all before i come on your question Please right your Name, I hope your name is Good and understandable.
if you want on click event Total column then need a javascript, with javascript i think not possible.
what you think this code.