Home Forums WinForms controls Xceed Grid for WinForms Cell comment icon like in Excel

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • User (Old forums)
    Post count: 23064
    #16760 |

    I have an application where when the user changes values in the cell they also provide a comment.  I would like the cell to then have the small triangle in the upper right corner like it does in Excel.  I do not need to have it respond to user mouse clicks, I just want the comment to display in the tooltip for the cell, but if there is a comment associated with the value in the cell(extra column returned from DB) then I would like the little triangle to appear.

    I see posts on how to make a cell an icon or image viewer, but that is not really what I would like to have.

    Imported from legacy forums. Posted by Brian (had 2075 views)

    User (Old forums)
    Post count: 23064

    You can derive from the DataRow/DataCell classes, and override the OnPaintForeground() method of the cell to draw the triangle as needed.

    Here is more information form the help documentation on extending these classes :




    Imported from legacy forums. Posted by André (had 333 views)

    User (Old forums)
    Post count: 23064

    Here is what I ended up with and it works great.  I think this is easier that creating a new derived class.

    This is Friend only because for me it is in a base class, could be private or public or whatever you need.
    Hook this to the Cell.Paint event for each of the cells in the DataRowTemplate.Cells collection.

    You will need to include your own check in the sub for which cell gets the indicator, used as is it will put the graphic in every cell.  I did not include the check since mine may not be like yours.

    I hope this helps someone else….

    For Each oCell As Xceed.Grid.Cell In mGridControl.DataRowTemplate.Cells
        AddHandler oCell.Paint, AddressOf AddCommentIndicator

         Friend Sub AddCommentIndicator(ByVal sender As Object, ByVal e As Xceed.Grid.GridPaintEventArgs)

            ‘Wrap the following in the conditional for you situation where you want the indicator drawn.
            Dim CellBrush As New SolidBrush(Color.Red)
                Dim TrianglePoints() As System.Drawing.PointF = {New PointF(e.DisplayRectangle.Right – 5, e.DisplayRectangle.Y), New PointF(e.DisplayRectangle.Right, e.DisplayRectangle.Y), New PointF(e.DisplayRectangle.Right + 5, e.DisplayRectangle.Y + 10)}
                e.Graphics.DrawPolygon(Pens.Red, TrianglePoints)
                e.Graphics.FillPolygon(CellBrush, TrianglePoints)
            Catch ex As Exception
            End Try

        End Sub

    Imported from legacy forums. Posted by Brian (had 2536 views)

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