In windows forms, I'm trying to fill a DataGridView
manually by inserting DataGridViewRows
to it, so my code looks like this:
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(dgvArticles);
row.Cells[0].Value = product.Id;
row.Cells[1].Value = product.Description;
.
.
.
dgvArticles.Rows.Add(row);
However, I would like to add the Cell value by column name instead of doing it by the index, something like this:
row.Cells["code"].Value = product.Id;
row.Cells["description"].Value = product.Description;
But doing it like that throws an error saying it couldn't find the column named "code".
I'm setting the DataGridView columns from the designer like this:
Am I doing something wrong? How can I accomplish what I want to do?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…