Good day experts, I am trying to use a list with four properties that can be accessed and modified by two different forms. The fields are the following:
public class Articulos
{
public String articulo { get; set; }
public int cantidadSolicitud { get; set; }
public int cantidadTomada { get; set; }
public String lote { get; set; }
}
And the class where the collection is:
public class ColeccionArticulos
{
//La colección contendrá la lista de artículos de la solicitud
public static List<Articulos> articulos;
public ColeccionArticulos()
{
//Creamos una lista vacía
articulos = new List<Articulos>();
}
//Se agrega un nuevo artículo a la lista
public void agregarArticulo(Articulos nuevoArticulo)
{
articulos.Add(nuevoArticulo);
}
}
In the form2 is where I create the instance:
public partial class Lotes : Form
{
public delegate void pasar(string dato);
public event pasar pasado;
Articulos a = new Articulos();
ColeccionArticulos articulos = new ColeccionArticulos();
And in a click event command call the following function:
public void ActualizarRegistro()
{
int loop = 0;
foreach (DataGridViewRow row in gridLotesDisponibles.Rows)
{
if (Convert.ToString(row.Cells[0].Value) != "")
{
a.articulo = lblArticulo.Text.ToString();
a.cantidadSolicitud = Int32.Parse(txtCantidadRequerida.Text.ToString(), NumberStyles.AllowThousands);
a.cantidadTomada = Int32.Parse(gridLotesDisponibles.Rows[loop].Cells[0].Value.ToString(), NumberStyles.AllowThousands);
a.lote = gridLotesDisponibles.Rows[loop].Cells[1].Value.ToString();
ColeccionArticulos.articulos.Add(a);
}
loop++;
}
pasado("Ventana generada por interfaz");
}
I have two problems that I have not been able to solve, the first is that within "articles" the DGV is traversed, however, only the data of the last row is stored, that is, when going through the following grid:
Only the last line is saved three times:
The second problem I have is that when you close the second window, press "Select lots" of another product and fill in the information of the corresponding batches, new information is stored but following the previous example, the 3 elements that already are created are deleted and do not leave them stored.
I do not know what I'm doing wrong on both points. I request your support to see if they can advise me something, guide me, or suggest an example or way to solve it.
Thanks in advance, best regards!