Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridView column valuetype to bitmap.
 

DataGridView column valuetype to bitmap.

Hi,

I have to set the GridColumn dynamically, when the form loads. I am setting one of the GridColumns to show the bitmaps by setting
DataGridView.ValueType = typeof(Bitmap)
and it always shows System.Drawing.Bitmap as text and never draws the bitmap.
I even tried
DataGridViewColumn dgvc = new DataGridViewImageColumn(false);
But that also didn't work.
I know, that I can override the cell paint method and draw bitmaps there. But, i am really interested in trying the inherent features that DataGridView has before overriding the methods.

Thanks,

-Brajesh

brajeshkumar69  Tuesday, May 01, 2007 7:16 PM

Hi

The following code example demonstrates how to extract an icon from an embedded resource and convert it to a bitmap for display in every cell of an image column. For another example that replaces textual cell values with corresponding images, see How to: Customize Data Formatting in the Windows Forms DataGridView Control.

Public Sub CreateGraphicsColumn()

Dim treeIcon As New Icon(Me.GetType(), "tree.ico")

Dim iconColumn As New DataGridViewImageColumn()

With iconColumn

.Image = treeIcon.ToBitmap()

.Name = "Tree"

.HeaderText = "Nice tree"

End With

dataGridView1.Columns.Insert(2, iconColumn)

End Sub

And here is another article about how to: Work with Image Columns in the Windows Forms DataGridView Control

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

Hope it helps

Regards

Gavin Jin - MSFT  Tuesday, May 08, 2007 7:47 AM

Hi

The following code example demonstrates how to extract an icon from an embedded resource and convert it to a bitmap for display in every cell of an image column. For another example that replaces textual cell values with corresponding images, see How to: Customize Data Formatting in the Windows Forms DataGridView Control.

Public Sub CreateGraphicsColumn()

Dim treeIcon As New Icon(Me.GetType(), "tree.ico")

Dim iconColumn As New DataGridViewImageColumn()

With iconColumn

.Image = treeIcon.ToBitmap()

.Name = "Tree"

.HeaderText = "Nice tree"

End With

dataGridView1.Columns.Insert(2, iconColumn)

End Sub

And here is another article about how to: Work with Image Columns in the Windows Forms DataGridView Control

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

Hope it helps

Regards

Gavin Jin - MSFT  Tuesday, May 08, 2007 7:47 AM

You can use google to search for other answers

Custom Search

More Threads

• dataGridView1_CellEndEdit problem
• sql server instances list
• How add parameters in sql query from textbox C#.net
• Activate/deactivate and format cells in a datagridview using a checkbox column
• picturebox image size
• i need to change the row position during run time using drag and drop method for data gridview
• DataGridViewComboBoxCell event problem
• How to focus other control after press the enter key in the last row of a DataGridVied control?
• How to use DataGridViewComboBoxColumn in vb.net 2005
• Scrolling 2 DataGridViews Simultaneously Using External ScrollBars