A
A
Alexander Sinelnikov2020-02-18 23:49:40
C++ / C#
Alexander Sinelnikov, 2020-02-18 23:49:40

DataGridVeiw addition calculator in columns?

Good day, please tell me how to implement a calculation in DataGridVeiw where the value of the first cell is set to a number in the second percentage and in the third the sum is displayed?5e4c4e53d41bd735396248.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twobomb, 2020-02-19
@Straj_ua

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            dataGridView1.CellEndEdit += dataGridView1_CellEndEdit;

        }

        public void recalculateRow(int rowInx){
         
            var zak = dataGridView1.Rows[rowInx].Cells[0].Value;   
            var perc = dataGridView1.Rows[rowInx].Cells[1].Value;
            dataGridView1.Rows[rowInx].Cells[2].Value = "";
            if (zak == null || perc == null)
                return;
            try{
                dataGridView1.Rows[rowInx].Cells[2].Value = float.Parse(zak.ToString()) + float.Parse(zak.ToString()) *  (float.Parse(perc.ToString())/100);
            }catch(FormatException e){

            }
        }
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)        {
            recalculateRow(e.RowIndex);
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question