Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Custom column text

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

Custom column text
Link Posted: 11-Feb-2006 01:25
I've done custom column class:
Public Class TreeVColumn
            Inherits TreeViewColumn
            'Public Overrides Sub PaintHeader(ByVal dci As CellDrawInfo)

            'End Sub

            

            Public Overrides Sub PaintCellValue(ByVal dci As CellDrawInfo)
                
                MyBase.ShowImages = True
                MyBase.EditorStyle = EditorStyle.Simple
                dci.Text.PadRight(10)
                Dim icona As New System.Drawing.Icon("C:\Program Files\VB\Resources\flygrid.ico")
                dci.g.DrawIcon(icona, 0, 0)
                dci.Text.Insert(2, "iiiiiii")
                MyBase.PaintCell(dci)
                Dim a = dci.backBrush
                Dim col As System.Drawing.Color
                col = System.Drawing.Color.FromName("Black")
                MyBase.CellForeColor = col
                MyBase.PaintTextInCell(dci, a, col)
                
            End Sub

End Class


but I see only tree and , text when try to edit cell, an do not see any image
Link Posted: 11-Feb-2006 08:33
This code incorrect, as you are trying to draw icon in the client area at point with (0,0) coordinates:

dci.g.DrawIcon(icona, 0, 0)

More correct code what draw icon in the 0,0 coordinates of cell rectangle:

dci.g.DrawIcon(icona, dci.cellRect.X, dci.cellrect.Y)


this code is also incorrect as dci.text can be Nothing(Null) and at this place can be throws exception:

dci.Text.Insert(2, "iiiiiii")


This code is also incorrect. If you want to specify custom color in this procedure, use dci.customForeColor

col = System.Drawing.Color.FromName("Black")
MyBase.CellForeColor = col
Link Posted: 12-Feb-2006 20:26
Text and image not shown, but cell looks like has split into two parts.
I'm trying to show icon and text in one cell, is code above the right way to do this?
Link Posted: 12-Feb-2006 23:41
This code is partially correct.
To correctly show text next to the image you should modify dci.cellRect before calling MyBase.PaintTextInCell(dci, a, col):

'....
dci.cellRect.Left = dci.cellRect.Left + icona.Width
dci.cellRect.Width = dci.cellRect.Width - icona.Width
MyBase.PaintTextInCell(dci, a, col)
'....

If you're planning to edit cells in this column, you should override GetEditableCellRect and modify returned by MyBase.GetEditableCellRect result also:

'....
Rectangle rect = MyBase.GetEditableCellRect(....)
rect.Left = rect.Left + icona.Width
rect.Width = rect.Width - icona.Width
Return rect
Link Posted: 13-Feb-2006 00:17
I've got message ,that dci.cellRect.Left is ReadOnly
Link Posted: 13-Feb-2006 00:50
Sorry, use dci.celRect.X instead of dci.celRect.Left:
'....
dci.cellRect.X = dci.cellRect.X + icona.Width
dci.cellRect.Width = dci.cellRect.Width - icona.Width
MyBase.PaintTextInCell(dci, a, col)
'....

and
'....
Rectangle rect = MyBase.GetEditableCellRect(....)
rect.X = rect.X + icona.Width
rect.Width = rect.Width - icona.Width
Return rect
Link Posted: 13-Feb-2006 02:13
this code gives no errors, but nothing changes - I don't see text or icon, only tree lines
Link Posted: 13-Feb-2006 02:28
Please send us (to ) your sample to give you recommendations and make code working correctly.
Link Posted: 13-Feb-2006 06:25
I've received your code, below is a correct code of column that displaying image in the cell next to the text:
Some comments: icon.ico file is added to the project as embedded resource. To determine its name in the managed resource of compiled assembly you can add default namespace of this project + [.] symbol + file name - FlyGridDemo.icon.ico. Or you can inspect compiled demo in the any assembly browser (our Spices.Net for example) and find resource name in the Resources section.
[VB.NET]
    Public Class ColumnWithImage
      Inherits Column

      Public Overloads Overrides Function GetEditableCellRect(ByVal location As System.Drawing.Point, ByVal context As NineRays.Windows.Forms.Grids.FlyGridViewPort, ByVal grid As NineRays.Windows.Forms.Grids.FlyGridViewPort, ByVal node As NineRays.Windows.Forms.Data.NodeBase) As System.Drawing.Rectangle
        Dim r As System.Drawing.Rectangle = MyBase.GetEditableCellRect(location, context, grid, node)
        If (Not Me.Icon Is Nothing) Then
          Dim iconWidth As Integer = Me.Icon.Width + 2
          r.X = r.X + iconWidth
          r.Width = r.Width - iconWidth
        End If
        Return r
      End Function

      Private _icon As System.Drawing.Icon = Nothing

      Public ReadOnly Property Icon() As System.Drawing.Icon
        Get
          If (_icon Is Nothing) Then
            ' this icon is added to this project as Embedded resource
            Dim icoStream As System.IO.Stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("FlyGridDemo.icon.ico")
            If (Not icoStream Is Nothing) Then
              _icon = New System.Drawing.Icon(icoStream)
            End If
          End If
          Return _icon
        End Get
      End Property

      Public Overrides Sub PaintCellValue(ByVal dci As CellDrawInfo)
        If (Not Me.Icon Is Nothing) Then
          dci.g.DrawIcon(Me.Icon, dci.cellRect.X, dci.cellRect.Y)
          dci.cellRect.X = dci.cellRect.X + Me.Icon.Width
          dci.cellRect.Width = dci.cellRect.Width - Me.Icon.Width
        End If
        MyBase.PaintCellValue(dci)
      End Sub
    End Class