1
votes

I have a Winforms application with a DataGridView.

The DataSource of the grid is set to a BindingSource. The DataSource of the BindingSource is a collection of objects, which implements the IBindingList interface. (Actually a SortableBindingList class based on a sample).

If I try to set the property AllowUserToAddRows on the grid, I get an error message "Property value is not valid" with additional details "Conversion from type 'Bitmap' to type 'Integer' is not valid."

Some of the columns in the grid show images, which are read-only.

What is this error message trying to tell me?

Are there some restrictions on the use of the property AllowUserToaddRows?

If it refers to a specific column in the grid, or a property in the class representing a row, how can I find out which column or property is causing the problem?

1
Some of the columns in the grid are custom image columns based on DataGridViewImageColumn, with custom cells based on DataGridViewImageCell. If I throw these columns out, then I can set the property AllowUserToAddRows. Does that mean I am doing something wrong in the custom column implementation?Phil Jollans

1 Answers

1
votes

I've got it.

The error message is an exception in the function GetFormattedValue() in the custom implementations of DataGridViewImageCell.

In all of the real cases, this function is called with an enum value, which is displayed as an image. The function casts the value to the relevant enum and then selects one of several images.

If you set AllowUserToAddRows=true, then the designer calls the function GetFormattedValue and passes an image in the value parameter. My (poor) code generates an exception.

I have now added some handling for this case, and I can set AllowUserToAddRows to true.