Home Forums WinForms controls Xceed Grid for WinForms Icon column, viewing & sorting

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #14421 |

    I’m trying to create an Icon type column in the grid.
    When i create a column type Icon without specifying a CellViewer for the cell, no icon is displayed. Instead i can see the word ‘(Icon)’ that appear in the cell even if i set the cell.value previously with a Icon object.

    So i try to create a custom CellViewer
    After setting the cellViewer to my icon type column, i can now see the icon in the cell.
    But the word ‘(Icon)’ still appear under the loaded icon.

    Also, when i sort this column, this has no effect. I want icons that are similar to be sorted together. Is this possible to sort icon column.

    So basically, i want to get rid of the word ‘(Icon)’ that appear under my Icon symbol and i want to be able to sort the icons together.

    Here’s my code…

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    LoadIcons()

    GridControl1.BeginInit()

    Dim c As New Xceed.Grid.Column(“Column1”, GetType(String))

    GridControl1.Columns.Add(c)

    Dim c2 As New Xceed.Grid.Column(“Column2”, GetType(String))

    GridControl1.Columns.Add(c2)

    Dim c3 As New Xceed.Grid.Column(“Icon”, GetType(Icon))
    c3.CellViewer = New IconViewer
    c3.DataComparer = New IconComparer

    GridControl1.Columns.Add(c3)

    GridControl1.EndInit()

    Dim dr As Xceed.Grid.DataRow = GridControl1.DataRows.AddNew()

    dr.Cells.Item(0).Value = “A”
    dr.Cells.Item(1).Value = “B”
    dr.Cells.Item(2).Value = Icons(0)
    dr.EndEdit()

    Dim dr2 As Xceed.Grid.DataRow = GridControl1.DataRows.AddNew()

    dr2.Cells.Item(0).Value = “1”
    dr2.Cells.Item(1).Value = “2”
    dr2.Cells.Item(2).Value = Icons(1)
    dr2.EndEdit()

    Dim dr3 As Xceed.Grid.DataRow = GridControl1.DataRows.AddNew()

    dr3.Cells.Item(0).Value = “Z”
    dr3.Cells.Item(1).Value = “Y”
    dr3.Cells.Item(2).Value = Icons(0)
    dr3.EndEdit()
    End Sub

    Private Sub LoadIcons()
    Dim i As Icon

    i = New Icon(“UserOffline16.ico”)

    Icons.Add(i)

    i = New Icon(“UserOnline16.ico”)

    Icons.Add(i)

    i = New Icon(“UserDisconnected16.ico”)

    Icons.Add(i)
    End Sub

    Public Class IconViewer
    Implements ICellViewer

    ‘ Returns the required height for the viewer.
    ‘ In this case, we return the height of the image so that it can be displayed properly.
    Function GetFittedHeight(ByVal cell As Cell, ByVal mode As AutoHeightMode) As Integer Implements ICellViewer.GetFittedHeight
    Return DirectCast(cell.Value, Icon).Height
    End Function

    ‘ Returns the required width for the viewer.
    ‘ -1 means that we don’t have any special requirements.
    Function GetFittedWidth(ByVal cell As Cell) As Integer Implements ICellViewer.GetFittedWidth
    Return -1
    End Function

    ‘ Paints the value of the cell. In our case, we will take the cell’s
    ‘ numeric value and draw the same number of images.
    Function PaintCellValue(ByVal e As GridPaintEventArgs, ByVal cell As Cell) As Boolean Implements ICellViewer.PaintCellValue
    Dim imageWidth As Integer = DirectCast(cell.Value, Icon).Width
    Dim horizontalPosition As Integer = 10
    e.Graphics.DrawImage(DirectCast(cell.Value, Icon).ToBitmap, horizontalPosition, e.DisplayRectangle.Y, imageWidth, e.DisplayRectangle.Height)
    End Function
    End Class

    Imported from legacy forums. Posted by Andre (had 1980 views)

    User (Old forums)
    Member
    Post count: 23064

    From what I understand, when you are overriding the PaintCellValue, you need to make sure that it returns True otherwise, the cell will continue to paint the value which is a ToString() of the dataType in this case.

    From the help file :

    Return Value
    true if the viewer painted the cell’s content; false if the viewer was not able to paint the cell’s content and wants the cell to paint itself.

    Imported from legacy forums. Posted by Matt (had 3033 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.