int i = 0;
string[] AbDates = new string[5];
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
string dt = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
if (string.IsNullOrEmpty(dt))
{
}
else
{
if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor == Color.Red)
{
if (MessageBox.Show("Do you want to UnMark this ?", "UnMark", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
{
}
else
{
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.White;
dt = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
AbDates = AbDates.Where(val => val != dt).ToArray();
i--;
}
}
else
{
if (MessageBox.Show("Do you want to Mark this As Absent?", "Absent", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
{
}
else
{
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.Red;
dt = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
//MessageBox.Show(i.ToString());
AbDates[i] = dt;
i++;
}
}
}
}
here is my code.. I have an array with size[5]. I added 5 values into this array and then removed the values. Now my array have only one value. If I add another value to this array it shows the error Index was outside the bounds of the array.