RobertoCarlos Melgar

RobertoCarlos Melgar

  • 1.8k
  • 112
  • 1.1k

Index -1 does not have a value

May 28 2020 1:58 PM
Hello dear, good afternoon. I have a small problem that I no longer know how to solve, I expose
I need to go from one DataGridView to another for this I have the following, I will only show you the image of the form to not be so extensive.
 
 
 
This is the code:
An Aux List
  1. public class AuxProducto  
  2.     {  
  3.         public int ProductoId { getset; }  
  4.         public string Codigo { getset; }  
  5.         public string ProductoDescripcion { getset; }  
  6.         public decimal PrecioVenta { getset; }  
  7.     }  
A List of the AuxProduct Class
  1. List<AuxProducto> ListaAuxProducto = new List<AuxProducto>();  
The datasource of the datagrid on the right is this
  1. private void CargarDatagriViewProdPrecioNuevo()  
  2.         {  
  3.             DataGridViewPrecioNuevo.DataSource = ListaAuxProducto;  
  4.         }  
 
 The button code that goes from one datagridview to another is this
 
  1. private void button1_Click(object sender, EventArgs e)  
  2.         {  
  3.             foreach (DataGridViewRow fila in DataGridViewPreciosAntiguo.Rows)  
  4.             {  
  5.                 AuxProducto auxProducto = new AuxProducto();  
  6.                 if (Convert.ToBoolean(fila.Cells["Select"].Value))  
  7.                 {  
  8.                     auxProducto.ProductoId = (int)fila.Cells["Id"].Value;  
  9.                     auxProducto.Codigo = fila.Cells["Codigo"].Value.ToString();  
  10.                     auxProducto.ProductoDescripcion = fila.Cells["ProductoDescripcion"].Value.ToString();  
  11.                     auxProducto.PrecioVenta = 0.00M;  
  12.                     ListaAuxProducto.Add(auxProducto);  
  13.                     DataGridViewPrecioNuevo.DataSource = null;  
  14.                     DataGridViewPrecioNuevo.DataSource = ListaAuxProducto;  
  15.                 }  
  16.             }  
  17.         }  
As you can see, everything does as it should be done, or maybe there is some error please let me know.
In the form on the right, I need to add a new price in the new column, when I click on any part of the datagridview I get the error
 
 
where can my mistake be please.
 
 
 I appreciate the collaboration,
 
Roberto 

Brought to you by: JavaScript SDK for Bold BI dashboard and analytics embedding. Free trial.

Answers (1)