Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to multiply data of two columns for third column in datagridview
    primarykey
    data
    text
    <p>I want to multiply the data of two columns and show it in the third column.</p> <p>For example:</p> <pre><code>1st Column: Quantity 2nd Column: Rate 3rd Column: Price </code></pre> <p>I want to multiply as user enters the data for quantity and rate like <code>Quantity=2</code>, <code>rate=50</code>automatically in price column I want <code>100</code> to be appear.</p> <p>Simultaneously I want to division as user enters the data for quantity and rate like <code>Price=100</code>, <code>rate=50</code>automatically in Quantity column I want <code>2</code> to be appear.</p> <p>And when a user enters the data for quantity and rate like <code>Price=100</code>, <code>Quantity=2</code>automatically in Rate column I want <code>50</code> to be appear.</p> <p>This three will happen in a same datagridview. User only enter any two field within this three and third will come automatically.</p> <p>Using C#, VS2008, SQL 2008</p> <pre><code>private void dataGridView2_CellEndEdit(object sender, DataGridViewCellEventArgs e) { int quantity,rate; for (int i = 0; i &lt; dataGridView2.Rows.Count; i++) { if(int.TryParse(dataGridView2.Rows[i].Cells[1].Value.ToString(), out quantity) &amp;&amp; int.TryParse(dataGridView2.Rows[i].Cells[2].Value.ToString(), out rate)) { int price = quantity * rate; dataGridView2.Rows[i].Cells[3].Value = price.ToString(); } } } </code></pre> <p>I write this code. There shows a error. Object reference not set to an instance of an object on </p> <pre><code>if(int.TryParse(dataGridView2.Rows[i].Cells[1].Value.ToString(), out quantity) &amp;&amp; int.TryParse(dataGridView2.Rows[i].Cells[2].Value.ToString(), out rate)) </code></pre> <p>this line.</p> <hr> <p><img src="https://i.stack.imgur.com/6lZZy.jpg" alt="enter image description here"></p> <p>I want to do like this. User can fill any 2 field among this 3. And third will take automatically. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload