Answer the question
In order to leave comments, you need to log in
Why does System.ArgumentNullException appear when I add values from the DataGridView to the listbox?
Error: System.ArgumentNullException: "Value cannot be null.
Parameter name: item"
for (int i = 0; i < filmsDataGridView.RowCount; i++)
{
listBox1.Items.Add(filmsDataGridView.Rows[i].Cells[7].Value);
}
Answer the question
In order to leave comments, you need to log in
Your error is due to the fact that filmsDataGridView.Rows[i].Cells[7].Value in some cases you have = null, and null cannot be inserted into CombopBox
Always convert nulls to an empty string like
or like this:
listBox1.Items.Add(filmsDataGridView.Rows[i].Cells[7].Value?.ToString() ?? String.Empty);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question