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

T.Zacks 3,996 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

Developer technologies Windows Forms
Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 90,521 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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.