Riki Dev

Riki Dev

  • NA
  • 5
  • 1k

Error system.indexoutofrangeexception on datagridview

Sep 19 2017 2:58 AM
Hello guys i have this error: Indexoutofrangeexception on this code:
 
  1. else if (comboBox1.Text == "CSV")  
  2.             {  
  3.                 try {  
  4.                     String CodArt, Descrizione, CodEAN = null, Immagine = null, fornitore = null;  
  5.                     decimal Prezzo;  
  6.                     int check = 0;  
  7.   
  8.                     //controllo se è stato selezionato un fornitore dalla datagridview  
  9.                     foreach (DataGridViewRow row in dataGridViewFornitore.Rows)  
  10.                     {  
  11.                         if (this.dataGridViewFornitore.SelectedRows.Count == 1)  
  12.                         {  
  13.                             check = 1;  
  14.                             // get information of 1st column from the row  
  15.                             fornitore = this.dataGridViewFornitore.SelectedRows[0].Cells[0].ToString();  
  16.                         }  
  17.                     }  
  18.   
  19.                     if (check == 1)  
  20.                     {  
  21.                         using (var rd = new StreamReader(labelPercorso.Text))  
  22.                         {  
  23.                             Articolo a = new Articolo();  
  24.                             a.db = this.db;  
  25.   
  26.                             while (!rd.EndOfStream)  
  27.                             {  
  28.                                 //setto codean e immagine =null ad ogni giro   
  29.                                 CodEAN = null;  
  30.                                 Immagine = null;  
  31.   
  32.                                 var splits = rd.ReadLine().Split(';');  
  33.                                 //-------------------  
  34.                                 CodArt = splits[0];  
  35.                                 Descrizione = splits[1];  
  36.                                 Prezzo = decimal.Parse(splits[2]);  
  37.   
  38.                                 try  
  39.                                 {  
  40.                                     CodEAN = splits[3];  
  41.                                     Immagine = splits[4];  
  42.   
  43.                                 }  
  44.                                 catch (Exception ex)  
  45.                                 {  
  46.                                     Console.WriteLine("Non è presente nè immagine nè codean");  
  47.                                 }  
  48.   
  49.                                 a.CodiceArticolo = CodArt;  
  50.                                 a.Descrizione = Descrizione;  
  51.                                 a.CodiceEAN = int.Parse(CodEAN);  
  52.                                 a.Immagine = Immagine;  
  53.                                 a.Fornitore = fornitore;  
  54.   
  55.                                 a.InserisciArticoloCSV();  
  56.                             }  
  57.                         }  
  58.   
  59.                         CaricamentoDataGridNonDisponbili();  
  60.                     }  
  61.   
  62.                     else  
  63.                     {  
  64.                         MessageBox.Show("Devi seleziona un fornitore");  
  65.                     }  
  66.   
  67.                 }  
  68.   
  69.                 catch(Exception ex)  
  70.                 {  
  71.                     MessageBox.Show("Errore " + ex);  
  72.                 }  
  73.               }  

Answers (1)