0

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' column 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 'total' 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();
        }
bAppA
  • 38
  • 5
Bran Smith
  • 59
  • 1
  • 2
  • 10
  • what is your exact issue. What do you mean by `I have done something like this but of no value.`? – Avijit Dec 26 '14 at 17:04
  • I selected dataGridView from toolbox and added columns.Then in .cs file of this form i get into " private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) " this function. But when I ran the code then control does not shift in this function. – Bran Smith Dec 26 '14 at 17:30

1 Answers1

1

Does this line is written in your designer's code?

this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick);

And also make public

public void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{          
  newFunc();
}
bAppA
  • 38
  • 5
  • Yeah this code is written in designer file. I have made it public but it does not resolve the issue. – Bran Smith Dec 26 '14 at 19:11
  • Checkout this [`CellContentClick event doesn't always work`](http://stackoverflow.com/questions/22489156/cellcontentclick-event-doesnt-always-work) – bAppA Dec 26 '14 at 19:33