How do i compare a gridview cell to a string and if they match output it to a variable and then go to the next cell and repeat. This is what i have so far but it doesn't seem to work
private void btnfinalize_Click(object sender, EventArgs e)
{
for (int i = 0; i < dataGridView1.Rows.Count; ++i)
{
if(dataGridView1.Rows[i].Cells[0].Value.ToString() == "Manga vol 1 - 5")
{
Global.Book1 = Int32.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());
}
else if (dataGridView1.Rows[i].Cells[0].Value.ToString() == "Manga vol 6-15")
{
Global.Book2 = Int32.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());
}
else if (dataGridView1.Rows[i].Cells[0].Value.ToString() == "Novels 1-199")
{
Global.Book3 = Int32.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());
}
else if (dataGridView1.Rows[i].Cells[0].Value.ToString() == "Novels 200-400")
{
Global.Book4 = Int32.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());
}
else if (dataGridView1.Rows[i].Cells[0].Value.ToString() == "Comics series mainstream")
{
Global.Book5 = Int32.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());
}
else if (dataGridView1.Rows[i].Cells[0].Value == "Comics series secondary")
{
Global.Book6 = Int32.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());
}
else if (dataGridView1.Rows[i].Cells[0].Value.ToString() == "Text book 1 semester/2 modules")
{
Global.Book7 = Int32.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());
}
else if (dataGridView1.Rows[i].Cells[0].Value.ToString() == "Text book module add-ons")
{
Global.Book8 = Int32.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());
}
else if (dataGridView1.Rows[i].Cells[0].Value.ToString() == "Hardcover")
{
Global.Hardcover = Int32.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());
}
}
i get a System.NullReferenceException: 'Object reference not set to an instance of an object.'
System.Windows.Forms.DataGridViewCell.Value.get returned null.
error