Binding DataGridViewImageColumn in DataGridView

Dear all,

I would like to binding (string or bool) data from database in DataGridViewImageColumn. However, i catch exception in DataGridView_Error event when i run it. Exception message is Formating error or Commit error.

Please help me to resolve my problems and give me example code if possible.
Thanks for your help.
Khiem Vo.

[342 byte] By [khiemvo] at [2007-12-16]
# 1
The Image column only supports binding to a byte array, not to a string or bool data. You'll need to manually convert the string or bool to an image in the CellFormatting event.

Hope this helps,
-mark
DataGridView Program Manager
Microsoft
This post is provided "as-is"

MarkRideout at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 2
The Image column only supports binding to a byte array, not to a string or bool data.


Maybe I've read this wrong but the example here (with the bitmaps )

http://winfx.msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_fxmclictl/html/a6e72c70-ce18-425f-828d-d57be6f96ab6.asp

( and I quote )

"...contains an image column named Priority that is bound to a data source containing the string values "high", "medium", and "low"...."

TheSmithz at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 3
Let me describe what that sample is doing -- In a DataGridViewImageColumn (called Priority) the data for that column is a string but in this case you want to show an image instead. So the example handles the CellFormatting event and replaces the string value with the appropriate image based upon the priority.

Handling the CellFormatting and converting the string to an image makes the DataGridViewImageColumn think it is really bound to an image, since you are changing the formatted value.

Hope this helps!
-mark
DataGridView Progam Manager
Microsoft
This post is provided "as-is"

MarkRideout at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 4
I keep getting the following error when I try to load the form.

"An error occurred creating the form. See Exception.InnerException for details. The error is: Parameter is not valid."

The error is on this part of the MDIParent

frmProjects.MdiParent = Me

Where frmProjects is the form containing the code from the link.

The database field is set to "Text" (system.string) & I have tried the datagridview with both string and image types.

Any help would be greatly appreciated.

Vwalla at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 5
Nevermind. I had to copy the .bmp files to the debug folder (same as .exe) & also set my default value for "Priority" (I set mine to 'Low') in the .xsd file.

Otherwise I would get errors.

Vwalla

Vwalla at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 6

great help - new URL link:

http://msdn2.microsoft.com/en-us/library/z1cc356h.aspx

thxx!

THughes at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...