Goran Bibic

Goran Bibic

  • 457
  • 2.9k
  • 192k

Error in my app...index column negativecsome help?

Mar 18 2019 11:20 AM
Error is here line 11 and line 12

row = (DataGridViewRow)roba_uslugeDataGridView.SelectedRows[i].Clone(); int intColIndex = 0;

Some help?
  1. Private void roba_uslugeDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)  
  2. {  
  3.     DataGridViewRow row = new DataGridViewRow();  
  4.   
  5.     for (int i = 0; i < roba_uslugeDataGridView.Rows.Count; i++)  
  6.     {  
  7.         row = (DataGridViewRow)roba_uslugeDataGridView.SelectedRows[i].Clone();  
  8.         int intColIndex = 0;  
  9.   
  10.         foreach (DataGridViewCell cell in roba_uslugeDataGridView.SelectedRows[i].Cells)  
  11.         {  
  12.             var ColIndex = dataGridView1.Rows.Add();  
  13.             dataGridView1.Rows[intColIndex].Cells["redni_broj"].Value = intColIndex + 1;  
  14.             dataGridView1.Rows[intColIndex].Cells["bar_kod"].Value = cell.Value.ToString();  
  15.             dataGridView1.Rows[intColIndex].Cells["sifra"].Value = cell.Value;  
  16.             dataGridView1.Rows[intColIndex].Cells["naziv_artikla"].Value = cell.Value;  
  17.             dataGridView1.Rows[intColIndex].Cells["cijena"].Value = cell.Value;  
  18.             dataGridView1.Rows[intColIndex].Cells["kolicina"].Value = "1";  
  19.             foreach (DataGridViewRow g1 in dataGridView1.Rows)  
  20.             {  
  21.                 g1.Cells["ukupno"].Value = (Convert.ToDouble(g1.Cells["kolicina"].Value) * Convert.ToDouble(g1.Cells["cijena"].Value)).ToString("0.00");  
  22.             }  
  23.             row.Cells[intColIndex].Value = cell.Value;  
  24.             intColIndex++;  
  25.         }  
  26.         dataGridView1.Rows.Add(row);  
  27.     }  
  28.     dataGridView1.AllowUserToAddRows = false;  
  29.     dataGridView1.Refresh();  
  30.   
  31. }  
 

Answers (1)