0

How to add comment to cell in DataGridView? I need to comment my values in the grid.

How to add comment to cell in DataGridView? I need to comment my values in grid

Chris
  • 8,527
  • 10
  • 34
  • 51
Sergey Khojoyan
  • 113
  • 1
  • 1
  • 5

2 Answers2

2

Each cell can have a tooltip by setting the .ToolTipText property of that cell. Something like this:

// Event for formatting cells when rendering the grid
void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    // Some logic for determining which cell this is in the row
    if ((e.ColumnIndex == this.dataGridView1.Columns["SomeColumn"].Index))
    {
        // Get a reference to the cell
        DataGridViewCell cell = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];

        // Set the tooltip text
        cell.ToolTipText = "some text";
    }
}
David
  • 208,112
  • 36
  • 198
  • 279
2

set ToolTipText property on either DataGridViewCell or DataGridViewColumn to whatever text you want.

Alireza
  • 10,237
  • 6
  • 43
  • 59