I want to add a single row to the datagridview. According to the data I entered on the line I added, the calculations specified in the class should be made. When I say add a new line, I want a new line to appear and calculations on the same class.
the first row insertion and calculation process is taking place.
but when I want to add a second line, the new line is not created.
I am sharing my sample codes with you. Please your support.
public MyDesktop()
{
InitializeComponent();
bindingSource1.DataSource = typeof(TEST);
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = bindingSource1;
dataGridView1.ToolClick += DataGridView1_ToolClick;
}
private void DataGridView1_ToolClick(object sender, ToolClickEventArgs e)
{
dataGridView1.AllowUserToAddRows = true;
dataGridView1.BeginEdit();
dataGridView1.SetValue(QUANTITY, dataGridView1.NewRowIndex, 1);
dataGridView1.SetValue(PRICE, dataGridView1.NewRowIndex, 1);
dataGridView1.EndEdit();
dataGridView1.AllowUserToAddRows = false;
}
public class TEST
{
public float _QUANTITY { get; set; }
public float QUANTITY {
get { return _QUANTITY; }
set {
_QUANTITY = value;
TOTAL_PRICE = value * PRICE; }
}
public float _PRICE { get; set; }
public float PRICE {
get { return _PRICE; }
set {
_PRICE = value;
TOTAL_PRICE = PRICE * value; }
}
public float TOTAL_PRICE { get; set; }
}
I want to add and delete row when I click the button.
I don't want the blank row to appear unless the button is clicked.
AllowUserToAddRows means the user can add rows. To add rows programmatically, just add the rows.
Please login first to submit.