Discussion:
DataGridView fails on binary data
(too old to reply)
AlexS
2007-06-03 14:53:29 UTC
Permalink
Maybe I am missing something simple, but I am getting internal exception in
FW 2.0/3.0 when setting data source for a grid to data table, which contains
binary data. Looks like grid wants to paint them as image and throws
exception when data are not image - see stack below (not complete).

How can I avoid this? At least ignore?

Is there some settings which tells grid to ignore such errors? I can't find
it.

I am handling DataError event, but it doesn't get called.

Any suggestions?


System.Drawing.dll!System.Drawing.Image.FromStream(System.IO.Stream
stream, bool useEmbeddedColorManagement, bool validateImageData) + 0x1a6
bytes
System.Drawing.dll!System.Drawing.ImageConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext
context, System.Globalization.CultureInfo culture, object value) + 0x89
bytes
System.Windows.Forms.dll!System.Windows.Forms.Formatter.FormatObjectInternal(object
value, System.Type targetType, System.ComponentModel.TypeConverter
sourceConverter, System.ComponentModel.TypeConverter targetConverter, string
formatString, System.IFormatProvider formatInfo, object formattedNullValue)
+ 0x2d5 bytes
System.Windows.Forms.dll!System.Windows.Forms.Formatter.FormatObject(object
value = {Dimensions:[256]}, System.Type targetType = {System.Drawing.Image},
System.ComponentModel.TypeConverter sourceConverter,
System.ComponentModel.TypeConverter targetConverter, string formatString,
System.IFormatProvider formatInfo, object formattedNullValue, object
dataSourceNullValue) + 0x77 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewCell.GetFormattedValue(object
value, int rowIndex = 0, ref System.Windows.Forms.DataGridViewCellStyle
cellStyle = {DataGridViewCellStyle { BackColor=Color [Window],
ForeColor=Color [ControlText], SelectionBackColor=Color [Highlight],
SelectionForeColor=Color [HighlightText], Font=[Font: Name=Microsoft Sans
Serif, Size=8.25, Units=3, GdiCharSet=204, GdiVerticalFont=False],
NullValue=System.Drawing.Bitmap, WrapMode=False, Alignment=MiddleCenter }},
System.ComponentModel.TypeConverter valueTypeConverter,
System.ComponentModel.TypeConverter formattedValueTypeConverter,
System.Windows.Forms.DataGridViewDataErrorContexts context = Formatting |
Display) + 0x138 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewImageCell.GetFormattedValue(object
value, int rowIndex, ref System.Windows.Forms.DataGridViewCellStyle
cellStyle = {DataGridViewCellStyle { BackColor=Color [Window],
ForeColor=Color [ControlText], SelectionBackColor=Color [Highlight],
SelectionForeColor=Color [HighlightText], Font=[Font: Name=Microsoft Sans
Serif, Size=8.25, Units=3, GdiCharSet=204, GdiVerticalFont=False],
NullValue=System.Drawing.Bitmap, WrapMode=False, Alignment=MiddleCenter }},
System.ComponentModel.TypeConverter valueTypeConverter,
System.ComponentModel.TypeConverter formattedValueTypeConverter,
System.Windows.Forms.DataGridViewDataErrorContexts context) + 0x34 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewCell.GetEditedFormattedValue(object
value, int rowIndex, ref System.Windows.Forms.DataGridViewCellStyle
dataGridViewCellStyle, System.Windows.Forms.DataGridViewDataErrorContexts
context) + 0xc9 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewCell.PaintWork(System.Drawing.Graphics
graphics = {System.Drawing.Graphics}, System.Drawing.Rectangle clipBounds,
System.Drawing.Rectangle cellBounds, int rowIndex = 0,
System.Windows.Forms.DataGridViewElementStates cellState = Displayed |
Selected | Visible, System.Windows.Forms.DataGridViewCellStyle cellStyle,
System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle =
{DataGridViewAdvancedBorderStyle { All=NotSet, Left=None, Right=Single,
Top=None, Bottom=Single }}, System.Windows.Forms.DataGridViewPaintParts
paintParts = All) + 0x63 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.PaintCells(System.Drawing.Graphics
graphics = {System.Drawing.Graphics}, System.Drawing.Rectangle clipBounds,
System.Drawing.Rectangle rowBounds, int rowIndex = 0,
System.Windows.Forms.DataGridViewElementStates rowState = Displayed |
Visible, bool isFirstDisplayedRow = true, bool isLastVisibleRow,
System.Windows.Forms.DataGridViewPaintParts paintParts = All) + 0x532 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.Paint(System.Drawing.Graphics
graphics = {System.Drawing.Graphics}, System.Drawing.Rectangle clipBounds,
System.Drawing.Rectangle rowBounds, int rowIndex = 0,
System.Windows.Forms.DataGridViewElementStates rowState = Displayed |
Visible, bool isFirstDisplayedRow = true, bool isLastVisibleRow = true) +
0x17a bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridView.PaintRows(System.Drawing.Graphics
g = {System.Drawing.Graphics}, System.Drawing.Rectangle boundingRect,
System.Drawing.Rectangle clipRect, bool singleHorizontalBorderAdded = false)
+ 0x38a bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridView.PaintGrid(System.Drawing.Graphics
g, System.Drawing.Rectangle gridBounds, System.Drawing.Rectangle clipRect,
bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded) + 0x2b9
bytes
AlexS
2007-06-03 15:46:12 UTC
Permalink
Some more details.

It appears exception is intercepted when app is running under VS2005
Express. In non-debug mode grid shows red-cross icons instead of binary
data.

However same exception is raised when tab page, where grid is located, is
closed:
---------------------------
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.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.
---------------------------
OK
---------------------------

Funny thing is that DataError event is handled (cancel = true; throw
exception = false), but is not called.

Any suggestions?
Post by AlexS
Maybe I am missing something simple, but I am getting internal exception
in FW 2.0/3.0 when setting data source for a grid to data table, which
contains binary data. Looks like grid wants to paint them as image and
throws exception when data are not image - see stack below (not complete).
How can I avoid this? At least ignore?
Is there some settings which tells grid to ignore such errors? I can't
find it.
I am handling DataError event, but it doesn't get called.
Any suggestions?
System.Drawing.dll!System.Drawing.Image.FromStream(System.IO.Stream
stream, bool useEmbeddedColorManagement, bool validateImageData) + 0x1a6
bytes
System.Drawing.dll!System.Drawing.ImageConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext
context, System.Globalization.CultureInfo culture, object value) + 0x89
bytes
System.Windows.Forms.dll!System.Windows.Forms.Formatter.FormatObjectInternal(object
value, System.Type targetType, System.ComponentModel.TypeConverter
sourceConverter, System.ComponentModel.TypeConverter targetConverter,
string formatString, System.IFormatProvider formatInfo, object
formattedNullValue) + 0x2d5 bytes
System.Windows.Forms.dll!System.Windows.Forms.Formatter.FormatObject(object
value = {Dimensions:[256]}, System.Type targetType =
{System.Drawing.Image}, System.ComponentModel.TypeConverter
sourceConverter, System.ComponentModel.TypeConverter targetConverter,
string formatString, System.IFormatProvider formatInfo, object
formattedNullValue, object dataSourceNullValue) + 0x77 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewCell.GetFormattedValue(object
value, int rowIndex = 0, ref System.Windows.Forms.DataGridViewCellStyle
cellStyle = {DataGridViewCellStyle { BackColor=Color [Window],
ForeColor=Color [ControlText], SelectionBackColor=Color [Highlight],
SelectionForeColor=Color [HighlightText], Font=[Font: Name=Microsoft Sans
Serif, Size=8.25, Units=3, GdiCharSet=204, GdiVerticalFont=False],
NullValue=System.Drawing.Bitmap, WrapMode=False,
Alignment=MiddleCenter }}, System.ComponentModel.TypeConverter
valueTypeConverter, System.ComponentModel.TypeConverter
formattedValueTypeConverter,
System.Windows.Forms.DataGridViewDataErrorContexts context = Formatting |
Display) + 0x138 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewImageCell.GetFormattedValue(object
value, int rowIndex, ref System.Windows.Forms.DataGridViewCellStyle
cellStyle = {DataGridViewCellStyle { BackColor=Color [Window],
ForeColor=Color [ControlText], SelectionBackColor=Color [Highlight],
SelectionForeColor=Color [HighlightText], Font=[Font: Name=Microsoft Sans
Serif, Size=8.25, Units=3, GdiCharSet=204, GdiVerticalFont=False],
NullValue=System.Drawing.Bitmap, WrapMode=False,
Alignment=MiddleCenter }}, System.ComponentModel.TypeConverter
valueTypeConverter, System.ComponentModel.TypeConverter
formattedValueTypeConverter,
System.Windows.Forms.DataGridViewDataErrorContexts context) + 0x34 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewCell.GetEditedFormattedValue(object
value, int rowIndex, ref System.Windows.Forms.DataGridViewCellStyle
dataGridViewCellStyle, System.Windows.Forms.DataGridViewDataErrorContexts
context) + 0xc9 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewCell.PaintWork(System.Drawing.Graphics
graphics = {System.Drawing.Graphics}, System.Drawing.Rectangle clipBounds,
System.Drawing.Rectangle cellBounds, int rowIndex = 0,
System.Windows.Forms.DataGridViewElementStates cellState = Displayed |
Selected | Visible, System.Windows.Forms.DataGridViewCellStyle cellStyle,
System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle =
{DataGridViewAdvancedBorderStyle { All=NotSet, Left=None, Right=Single,
Top=None, Bottom=Single }}, System.Windows.Forms.DataGridViewPaintParts
paintParts = All) + 0x63 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.PaintCells(System.Drawing.Graphics
graphics = {System.Drawing.Graphics}, System.Drawing.Rectangle clipBounds,
System.Drawing.Rectangle rowBounds, int rowIndex = 0,
System.Windows.Forms.DataGridViewElementStates rowState = Displayed |
Visible, bool isFirstDisplayedRow = true, bool isLastVisibleRow,
System.Windows.Forms.DataGridViewPaintParts paintParts = All) + 0x532 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.Paint(System.Drawing.Graphics
graphics = {System.Drawing.Graphics}, System.Drawing.Rectangle clipBounds,
System.Drawing.Rectangle rowBounds, int rowIndex = 0,
System.Windows.Forms.DataGridViewElementStates rowState = Displayed |
Visible, bool isFirstDisplayedRow = true, bool isLastVisibleRow = true) +
0x17a bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridView.PaintRows(System.Drawing.Graphics
g = {System.Drawing.Graphics}, System.Drawing.Rectangle boundingRect,
System.Drawing.Rectangle clipRect, bool singleHorizontalBorderAdded =
false) + 0x38a bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridView.PaintGrid(System.Drawing.Graphics
g, System.Drawing.Rectangle gridBounds, System.Drawing.Rectangle clipRect,
bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded) + 0x2b9
bytes
ClayB
2007-06-04 09:13:08 UTC
Permalink
You can hide the column using code like:

this.dataGridView1.Columns["BinaryCol"].Visible = false;

===================
Clay Burch
Syncfusion, Inc.
no no
2010-12-30 11:12:28 UTC
Permalink
Hi there,
Did you ever get to know what was causing the problem?
I'm having the type of problem (I use MySQl though): looks like system trying to paint images, have red crosses etc...
I use a UNION SQL query which I mention becaus eerror only started once I started to use this. The Union query mixes dates and string ("Total" row at bottom), could be the problem?
I'm having this problem on Visual Basic Express 2008...
Let me know please (I can't hide the column)
Tx
Post by AlexS
Maybe I am missing something simple, but I am getting internal exception in
FW 2.0/3.0 when setting data source for a grid to data table, which contains
binary data. Looks like grid wants to paint them as image and throws
exception when data are not image - see stack below (not complete).
How can I avoid this? At least ignore?
Is there some settings which tells grid to ignore such errors? I can't find
it.
I am handling DataError event, but it doesn't get called.
Any suggestions?
System.Drawing.dll!System.Drawing.Image.FromStream(System.IO.Stream
stream, bool useEmbeddedColorManagement, bool validateImageData) + 0x1a6
bytes
System.Drawing.dll!System.Drawing.ImageConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext
context, System.Globalization.CultureInfo culture, object value) + 0x89
bytes
System.Windows.Forms.dll!System.Windows.Forms.Formatter.FormatObjectInternal(object
value, System.Type targetType, System.ComponentModel.TypeConverter
sourceConverter, System.ComponentModel.TypeConverter targetConverter, string
formatString, System.IFormatProvider formatInfo, object formattedNullValue)
+ 0x2d5 bytes
System.Windows.Forms.dll!System.Windows.Forms.Formatter.FormatObject(object
value = {Dimensions:[256]}, System.Type targetType = {System.Drawing.Image},
System.ComponentModel.TypeConverter sourceConverter,
System.ComponentModel.TypeConverter targetConverter, string formatString,
System.IFormatProvider formatInfo, object formattedNullValue, object
dataSourceNullValue) + 0x77 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewCell.GetFormattedValue(object
value, int rowIndex = 0, ref System.Windows.Forms.DataGridViewCellStyle
cellStyle = {DataGridViewCellStyle { BackColor=Color [Window],
ForeColor=Color [ControlText], SelectionBackColor=Color [Highlight],
SelectionForeColor=Color [HighlightText], Font=[Font: Name=Microsoft Sans
Serif, Size=8.25, Units=3, GdiCharSet=204, GdiVerticalFont=False],
NullValue=System.Drawing.Bitmap, WrapMode=False, Alignment=MiddleCenter }},
System.ComponentModel.TypeConverter valueTypeConverter,
System.ComponentModel.TypeConverter formattedValueTypeConverter,
System.Windows.Forms.DataGridViewDataErrorContexts context = Formatting |
Display) + 0x138 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewImageCell.GetFormattedValue(object
value, int rowIndex, ref System.Windows.Forms.DataGridViewCellStyle
cellStyle = {DataGridViewCellStyle { BackColor=Color [Window],
ForeColor=Color [ControlText], SelectionBackColor=Color [Highlight],
SelectionForeColor=Color [HighlightText], Font=[Font: Name=Microsoft Sans
Serif, Size=8.25, Units=3, GdiCharSet=204, GdiVerticalFont=False],
NullValue=System.Drawing.Bitmap, WrapMode=False, Alignment=MiddleCenter }},
System.ComponentModel.TypeConverter valueTypeConverter,
System.ComponentModel.TypeConverter formattedValueTypeConverter,
System.Windows.Forms.DataGridViewDataErrorContexts context) + 0x34 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewCell.GetEditedFormattedValue(object
value, int rowIndex, ref System.Windows.Forms.DataGridViewCellStyle
dataGridViewCellStyle, System.Windows.Forms.DataGridViewDataErrorContexts
context) + 0xc9 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewCell.PaintWork(System.Drawing.Graphics
graphics = {System.Drawing.Graphics}, System.Drawing.Rectangle clipBounds,
System.Drawing.Rectangle cellBounds, int rowIndex = 0,
System.Windows.Forms.DataGridViewElementStates cellState = Displayed |
Selected | Visible, System.Windows.Forms.DataGridViewCellStyle cellStyle,
System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle =
{DataGridViewAdvancedBorderStyle { All=NotSet, Left=None, Right=Single,
Top=None, Bottom=Single }}, System.Windows.Forms.DataGridViewPaintParts
paintParts = All) + 0x63 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.PaintCells(System.Drawing.Graphics
graphics = {System.Drawing.Graphics}, System.Drawing.Rectangle clipBounds,
System.Drawing.Rectangle rowBounds, int rowIndex = 0,
System.Windows.Forms.DataGridViewElementStates rowState = Displayed |
Visible, bool isFirstDisplayedRow = true, bool isLastVisibleRow,
System.Windows.Forms.DataGridViewPaintParts paintParts = All) + 0x532 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.Paint(System.Drawing.Graphics
graphics = {System.Drawing.Graphics}, System.Drawing.Rectangle clipBounds,
System.Drawing.Rectangle rowBounds, int rowIndex = 0,
System.Windows.Forms.DataGridViewElementStates rowState = Displayed |
Visible, bool isFirstDisplayedRow = true, bool isLastVisibleRow = true) +
0x17a bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridView.PaintRows(System.Drawing.Graphics
g = {System.Drawing.Graphics}, System.Drawing.Rectangle boundingRect,
System.Drawing.Rectangle clipRect, bool singleHorizontalBorderAdded = false)
+ 0x38a bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridView.PaintGrid(System.Drawing.Graphics
g, System.Drawing.Rectangle gridBounds, System.Drawing.Rectangle clipRect,
bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded) + 0x2b9
bytes
Post by AlexS
Some more details.
It appears exception is intercepted when app is running under VS2005
Express. In non-debug mode grid shows red-cross icons instead of binary
data.
However same exception is raised when tab page, where grid is located, is
---------------------------
DataGridView Default Error Dialog
---------------------------
System.ArgumentException: Parameter is not valid.
at System.Drawing.Image.FromStream(Stream stream, Boolean
useEmbeddedColorManagement, Boolean validateImageData)
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.
---------------------------
OK
---------------------------
Funny thing is that DataError event is handled (cancel = true; throw
exception = false), but is not called.
Any suggestions?
Post by ClayB
this.dataGridView1.Columns["BinaryCol"].Visible = false;
===================
Clay Burch
Syncfusion, Inc.
Submitted via EggHeadCafe
Oracle Developer For Beginners
http://www.eggheadcafe.com/training-topic-area/Oracle-SQL-Developer/2/Oracle-SQL-Samples.aspx
Loading...