Insert rows in a specified column for each row created previously

0

Good morning, my problem is that I'm working on a project, where I'm using DataGrids and I run into a problem: The user enters information in textbox give "add" and generates a row with the information of textboxs , now what I want to do is that for each row created fill me in the column empty with the data of a textbox fixed (Is another button not the one to add) How could you do it?

This is the code of the "Add" button:

{
     if (descuento.Text == string.Empty)
     {
         descuento.Text = "0";
     }
     dataGridView1.Rows.Add(prodcod.Text, articulo.Text, unidad.Text, preciou.Text, cantidad.Text, subtotal.Text, descuento.Text, total.Text);
     prodcod.Clear();
     articulo.Clear();
     unidad.Clear();
     preciou.Clear();
     cantidad.Clear();
     subtotal.Clear();
     descuento.Clear();
     total.Clear();
     prodcod.Focus();                      
}
    
asked by p0ncho14 05.04.2018 в 18:41
source

1 answer

1

If I understood what you want is to add a fixed value to each row added by taking the value that contains a TextBox :

In the event Click of your other button, put something like this:

private void otro_boton_Click(object sender, EventArgs e)
{
    if (dataGridView1.Rows.Count > 0)
    {
        for (int indice = 0; indice < dataGridView1.Rows.Count; indice++)
        {
             dataGridView1.Rows[indice].Cells[8].Value = tuTextBoxFijo.Text;
        }
     }
     else
        MessageBox.Show("No hay filas agregadas.");
}
  

Cells[8] represents column ID taken by its current position in the image.

    
answered by 05.04.2018 / 19:03
source