I am getting the following error:
DataGridView Default Error Dialog
The following exception occurred in the DataGridView:System.ArgumentException: Parameter is not valid.
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement)
at System.Drawing.Image.FromStream(Stream stream)
at System.Drawing.ImageConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at System.Windows.Forms.Formatter.FormatObjectInternal(Object value, Type targetType, TypeConverter sourceConverter, TypeConverter targetConverter, String formatString, IFormatProvider formatInfo, Object formattedNullValue)
at System.Windows.Forms.Formatter.FormatObject(Object value, Type targetType, TypeConverter sourceConverter, TypeConverter targetConverter, String formatString, IFormatProvider formatInfo, Object formattedNullValue, Object dataSourceNullValue)
at System.Windows.Forms.DataGridViewCell.GetFormattedValue(Object value, Int32 rowIndex, DataGridViewCellStyle& cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context) To replace this default dialog please handle the DataError event.
I have created a class
[DataContract]
public class Document : INotifyPropertyChanged
{
[DataMember]
private string _name;
[DataMember]
private DateTime _addedOn;
[DataMember]
private string _extension;
[DataMember]
private byte[] _content;
public event PropertyChangedEventHandler PropertyChanged = delegate { };
public Document()
{
_name = String.Empty;
_extension = String.Empty;
_content = null;
_addedOn = DateTime.Now;
}
public string Name
{
get { return _name; }
set
{
_name = value;
OnPropertyChanged("Name");
}
}
public DateTime AddedOn
{
get { return _addedOn; }
set
{
_addedOn = value;
OnPropertyChanged("AddedOn");
}
}
public string Extension
{
get { return _extension; }
set
{
_extension = value;
OnPropertyChanged("Extension");
}
}
public Byte[] Content
{
get { return _content; }
set
{
_content = value;
OnPropertyChanged("Content");
}
}
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
/// <summary>
/// Gets a value indicating if this document has already been submitted
/// to BancServ.
/// </summary>
public bool Processed
{
get
{
return (_content == null || _content.Length == 0);
}
}
}
I am binding a list of the above class to a datagridview and then I am getting the above error in the following section( it is a simple binding )
protected override void OnInitialize()
{
try
{
_documentsGridView.DataSource = this.Data.Documents;
base.OnInitialize();
}
catch (Exception ex)
{
}
}
void btnBrowse_Click(object sender, EventArgs e)
{
try
{
Document document = this.Data.RequestDocument(FileKind.Browse, "Pdf files|*.pdf");
this.Data.Documents.Add(document);
}
catch (Exception ex)
{
}
}
Here I am browsing a *.pdf files and providing the info of the .pdf file in a datagridview by the list.