adding images to grid columns? .net 1.1

G

Guest

I have a windows forms .net 1.1 question:
I tried adding an image (a picturebox) to a column in my grid, but haven't
been able to do it adequately. The pictures are there, but they don't seem
to be visible until I click on a cell and then the picture is visible. Not
sure what's going on.
Can you tell from the following code, or is there a better way:

Sub DoAssessmentGrid()
If bus.AssessmentList(ActionRequested.CaseNumber) Then
Dim ts As DataGridTableStyle
ts = dgAssessments.TableStyles(0)
ts.MappingName = "ClientAssessments"

Dim booleanColumn As DataGridBoolColumn
booleanColumn = ts.GridColumnStyles.Item("CompleteBool")
booleanColumn.TrueValue = True
booleanColumn.FalseValue = False
booleanColumn.NullValue = Convert.DBNull

Try
Dim executing_assembly As System.Reflection.Assembly =
Me.GetType.Assembly.GetEntryAssembly()
Dim my_namespace As String =
executing_assembly.GetName().Name.ToString()
If Not ts.GridColumnStyles.Item("Action") Is Nothing Then
ActionColumn = CType(ts.GridColumnStyles.Item("Action"),
DataGridTextBoxColumn)
ActionColumn.Alignment = HorizontalAlignment.Center
imgEdit = New PictureBox
imgExport = New PictureBox
Dim curDir As String = Environment.CurrentDirectory()
imgEdit.Image =
Image.FromFile("D:\OKDHS\AGING\ELDERS\ELDERSRemote\images\Edit.gif")
imgEdit.Cursor = Cursors.Arrow
imgEdit.SendToBack()
imgExport.Image =
Image.FromFile("D:\OKDHS\AGING\ELDERS\ELDERSRemote\images\btnExport.gif")
imgExport.Cursor = Cursors.Arrow
imgExport.SendToBack()
ActionColumn.TextBox.Controls.Add(imgEdit)
imgEdit.BringToFront()
'ActionColumn.Width = 65
'ActionColumn.TextBox.Controls.Add(imgExport)
End If

Catch ex As System.IO.FileNotFoundException
SystemMessage.Tell("Couldn't find one of the image files for
the grid")
Catch ex As Exception
End Try

dgAssessments.DataSource = bus.ObjectDataSet
dgAssessments.DataMember = ts.MappingName
End If
End Sub
 
C

Claes Bergefall

You are adding your image as a a control (PictureBox) to the textbox
contained in a DataGridTextBoxColumn. That textbox, and hence your
picturebox, is only visible when the cell is active. When the cell is not
active the content is drawn by the overriden Paint method in
DataGridTextBoxColumn.

You need to create you own class derived from DataGridColumnStyle and
override it's Paint method. Item 5.24 in the FAQ found here might help:
http://www.syncfusion.com/faq/windowsforms/Default.aspx

/claes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top