title: How to add a Label to a DataGridView cell
body: <p>Is there any way to insert a Label to DataGridView cell at runtime - say for example I wanted a little red number in the top corner of each cell? Do I need to create a new DataGridViewColumn type or can I just add a Label there when I'm populating the DataGridView?</p>
  
  <p><strong>EDIT</strong> I am now attempting to do this using Cell painting as per Neolisk's suggestion, but am unsure how to actually get the label to be displayed. I have the following code, where I now add the label text as the cell's <code>Tag</code> before setting its <code>Value</code>:</p>
  
  <pre><code>private void dgvMonthView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  {
      DataGridView dgv = this.dgvMonthView;
      DataGridViewCell cell = dgv[e.ColumnIndex, e.RowIndex];
  
      Label label = new Label();
      label.Text = cell.Tag.ToString();
      label.Font = new Font("Arial", 5);
      label.ForeColor = System.Drawing.Color.Red;
  }
  </code></pre>
  
  <p>Can anyone explain how I can now "attach" <code>label</code> to <code>cell</code>?</p>
  
  <p><strong>EDIT 2 - Solution</strong> I couldn't quite get it to work the above way, so have ended up subclassing the DataGridViewColumn and Cell and overriding the <code>Paint</code> event there to add whatever text is stored in <code>Tag</code> using DrawString rather than a Label as per neolisk's suggestion:</p>
  
  <pre><code>class DataGridViewLabelCell : DataGridViewTextBoxCell
  {
      protected override void Paint(Graphics graphics,
                                    Rectangle clipBounds,
                                    Rectangle cellBounds,
                                    int rowIndex,
                                    DataGridViewElementStates cellState,
                                    object value,
                                    object formattedValue,
                                    string errorText,
                                    DataGridViewCellStyle cellStyle,
                                    DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                    DataGridViewPaintParts paintParts)
      {
          // Call the base class method to paint the default cell appearance.
          base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState,
              value, formattedValue, errorText, cellStyle,
              advancedBorderStyle, paintParts);
  
          if (base.Tag != null)
          {
              string tag = base.Tag.ToString();
              Point point = new Point(base.ContentBounds.Location.X, base.ContentBounds.Location.Y);
              graphics.DrawString(tag, new Font("Arial", 7.0F), new SolidBrush(Color.Red), cellBounds.X + cellBounds.Width - 15, cellBounds.Y);
          }
      }
  }
  
  public class DataGridViewLabelCellColumn : DataGridViewColumn
  {
      public DataGridViewLabelCellColumn()
      {
          this.CellTemplate = new DataGridViewLabelCell();
      }
  }
  </code></pre>
  
  <p>Implemented as:</p>
  
  <pre><code>DataGridViewLabelCellColumn col = new DataGridViewLabelCellColumn();
  dgv.Columns.Add(col);
  col.HeaderText = "Header";
  col.Name = "Name"; 
  </code></pre>