I have a DataGridView of type 'DataGridViewTextBoxColumn' in which following fields are there :
SrNo. | Description | HSNCode | Qty | Rate | Amount
I want allow the user to enter the item Description , Qty and Rate
The "SrNo." column is read only
I want to generate the SrNo. automatically as the user enters to "Description" cell i.e. I want to display the row index in that cell.
And also I want to calculate the "Amount" (Qty*Rate) in my program as user leaves the "Qty" field.
I tried the following code :
private void grdData_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
if (e.ColumnIndex == 0)
{
grdData.Rows[e.RowIndex].Cells[0].Value = e.RowIndex.ToString();
}
else if (e.ColumnIndex == 5)
{
grdData.Rows[e.RowIndex].Cells[5].Value =
((Convert.ToDouble(grdData.Rows[e.RowIndex].Cells[3])) *
(Convert.ToDouble(grdData.Rows[e.RowIndex].Cells[4]));
}
}
}
How to do so?