Add content from rows of a DataGridView and unstick it in a Textbox

3

I am developing an application for the control of labels for the company where I work. I am working with a DataGridView which stores the data entered from the first Textbox as shown in the following image:

What you do until you press the "insert" button adds a new row with the values given in each TextBox.

What I intend to do is that also at the moment of pressing the "insert" button they are added by column and show the total result of the sum of each column in each of the Textbox that corresponds to them.

I do not know if there is any way for that that can be of my help. Greetings.

Thank you.

    
asked by Ezequie Lopez 09.08.2018 в 19:42
source

1 answer

3

Here you have an example in code of how to add the values of the cells of each column

//Realizo la suma de cada columna        
for (int numColumna = 0; numColumna < dataGridView1.Columns.Count; numColumna++)
        {
           var sumTotal= 0;           
           foreach (DataGridViewRow row in dataGridView1.Rows)
           {

               sumTotal += Convert.ToInt32(row.Cells[numColumna].Value);
           }

           textBox1.Text = sumTotal.ToString();//Aqui en cada iteración del for deberia ser el textbox correspondiente
        }

I hope it serves you. Greetings.

    
answered by 09.08.2018 / 20:30
source