C# DataGridView: How to set excel like comment red glyph in cell

T.Zacks 3,986 Reputation points
2021-08-23T16:04:07.447+00:00

I am working with datagridview and now attaching text as a comment in cell tag property and when user mouse over there i am showing that comment text in tooltips but i want to place a red glyph at the bottom right corner of the cell like excel. i searched a lot google but found no solution. so please help me with sample code to achieve my goal.

Thanks

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,846 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,354 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 81,861 Reputation points
    2021-08-23T17:04:24.81+00:00

    You can draw in CellPainting
    A test by drawing a triangle in the cell (1,1) :

    125751-dgv-cellpainting.jpg

    dataGridView1.CellPainting += new System.Windows.Forms.DataGridViewCellPaintingEventHandler(dataGridView1_CellPainting);  
    

    CellPainting :

    private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)  
    {  
        if (e.ColumnIndex == 1 && e.RowIndex == 1)  
        {  
            e.PaintBackground(e.CellBounds, true);  
            e.PaintContent(e.CellBounds);  
            using (SolidBrush brush = new SolidBrush(Color.FromArgb(255, 0, 0)))  
            {  
                Point[] pt = new Point[] { new Point(e.CellBounds.Right - 1, e.CellBounds.Bottom - 10), new Point(e.CellBounds.Right - 1, e.CellBounds.Bottom - 1), new Point(e.CellBounds.Right - 10, e.CellBounds.Bottom - 1) };  
                e.Graphics.FillPolygon(brush, pt);  
            }  
            e.Handled = true;  
        }  
    }  
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful