Ver Mensaje Individual
  #4 (permalink)  
Antiguo 04/09/2008, 13:43
lreyesg007
 
Fecha de Ingreso: marzo-2005
Mensajes: 123
Antigüedad: 19 años, 2 meses
Puntos: 1
Respuesta: datagrid con imagen VS 2003 .NET

No me muestra nada :(

Esto puse en el formulario

Dim ts As New DataGridTableStyle
ts.MappingName = "ParentTable"

Dim ImageCol As New ImageColumnStyle '<-- Name of class
With ImageCol
.ImageList = ImageList1 '<-- My imagelist object
.BackColor = Brushes.White
.ForeColor = Brushes.Black
.RightToLeft = True
.MappingName = "Icon"
.HeaderText = ""
.Width = ImageList1.ImageSize.Width + 4
.Alignment = HorizontalAlignment.Center
.ReadOnly = True
End With
ts.GridColumnStyles.Add(ImageCol)
DataGrid1.DataSource = ds.Tables(0)
DataGrid1.TableStyles.Add(ts)
DataGrid1.Refresh()

y esta es la clase

Imports System.Drawing
Imports System
Imports System.Windows.Forms
Public Class ImageColumnStyle
Inherits DataGridColumnStyle
Public ImageList As ImageList
Private Image As Image
Private bBackcolor As Brush
Private bForeColor As Brush
Private bRightToLeft As Boolean
Protected Overrides Sub Abort(ByVal rowNum As Integer)
Invalidate()
End Sub
Protected Overrides Function Commit(ByVal dataSource As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Boolean
Return True
End Function
Protected Overloads Overrides Sub Edit(ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal bounds As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean)
End Sub
Protected Overrides Function GetMinimumHeight() As Integer
Return ImageList.ImageSize.Height
End Function
Protected Overrides Function GetPreferredHeight(ByVal g As System.Drawing.Graphics, ByVal value As Object) As Integer
Return ImageList.ImageSize.Height
End Function
Protected Overrides Function GetPreferredSize(ByVal g As System.Drawing.Graphics, ByVal value As Object) As System.Drawing.Size
Return ImageList.ImageSize
End Function
Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer)
Paint(g, bounds, source, rowNum, BackColor, ForeColor, RightToLeft)
End Sub
Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal alignToRight As Boolean)

End Sub
Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal BackBrush As Brush, ByVal ForeBrush As Brush, ByVal alignToRight As Boolean)
Dim index = GetColumnValueAtRow(source, rowNum)
If Not IsDBNull(index) Then
InitImage(index)
Dim rect As Rectangle = New Rectangle(bounds.Location, ImageList.ImageSize)
g.FillRectangle(BackBrush, bounds)
g.DrawImage(Image, rect)
End If
End Sub
Private Sub InitImage(ByVal index As Integer)
If Not IsDBNull(ImageList) And ImageList.Images.Count >= index + 1 Then
Image = ImageList.Images(index)
End If
End Sub
Property BackColor() As Brush
Get
Return BackColor
End Get
Set(ByVal Value As Brush)
bBackcolor = Value
End Set
End Property
Property ForeColor() As Brush
Get
Return ForeColor
End Get
Set(ByVal Value As Brush)
bForeColor = Value
End Set
End Property
Property RightToLeft() As Boolean
Get
Return RightToLeft
End Get
Set(ByVal Value As Boolean)
bRightToLeft = Value
End Set
End Property
End Class


Ayuda por favor.... gracias