9
Reply

index was out of range. must be non-negative

Mega Saraswati

Mega Saraswati

Jun 25 2015 10:41 PM
501
hello guys.. I'm mega in Indonesia. sorry for my english so bad..  I have script like :
 
private void btnDelete_Click(object sender, EventArgs e)
{
if (idx != -1)
{

int yy = Int32.Parse(txtTotal1.Text);
int ap = yy - Convert.ToInt16(arTotal[idx].ToString());
txtTotal1.Text = ap.ToString();
arId.RemoveAt(idx);
arNama.RemoveAt(idx);
arHarga.RemoveAt(idx);
arBanyak.RemoveAt(idx);
arTotal.RemoveAt(idx);
}
listView1.Items.Clear();
for (int i = 0; i < this.arId.Count; i++)
{
listView1.Items.Add(new ListViewItem(new string[] { arId[i].ToString(), arNama[i].ToString(), arHarga[i].ToString(), arBanyak[i].ToString(), arTotal[i].ToString() }));
}
}
 
but error in "int ap = yy - Convert.ToInt16(arTotal[idx].ToString());" can you help me ?

Answers (9)