I have a DataGridView with some text columns, combo box columns and an image column. When I try to add a blank new row by calling DataGridView1.Rows.AddCopy(0)
I get the following error: System.FormatException: Formatted value of the cell has a wrong type.
The new row does not contain any data. When the user adds a new row through the GUI (ie not programmatically) there is no problem. Does anyone have any ideas as to what might be causing this issue?
Does this help?
// Create a new row on a datagridview
var rowId = dataGridView1.Rows.Add();
// fill the cells in the newly created row with your data
dataGridView1.Rows[rowId].Cells[ColumnText.Name].Value = "";
dataGridView1.Rows[rowId].Cells[ColumnCheckbox.Name].Value = true;
dataGridView1.Rows[rowId].Cells[ColumnImage.Name].Value = null; // add image
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.