I am dynamically adding a DataGridViewCheckBoxColumn to my DataGridView.
However, I can’t seem to add the tooltip to the checkboxes:
// Method to Populate the DataGrid
private void PopulateDataGrid(objPatient patient)
{
this.uiDocumentDataGrid.DataSource = DataManager.GetDocumentData(patient);
// Hide unnecessary columns
this.uiDocumentDataGrid.Columns["Forename"].Visible = false;
this.uiDocumentDataGrid.Columns["Surname"].Visible = false;
// Add column for selection
DataGridViewCheckBoxColumn selectedColumn = new DataGridViewCheckBoxColumn();
selectedColumn.Name = "Selected";
selectedColumn.HeaderText = "Attach";
selectedColumn.ReadOnly = false;
this.uiDocumentDataGrid.Columns.Insert(0,selectedColumn);
// Set columns except checkbox to readonly
foreach(DataGridViewColumn c in this.uiDocumentDataGrid.Columns)
{
if (c.Index > 0)
{
c.ReadOnly = true;
}
}
// Refresh the view in case of draw issues
this.uiDocumentDataGrid.Refresh();
// Add tooltip to each checkbox
foreach (DataGridViewRow r in uiDocumentDataGrid.Rows)
{
r.Cells["Selected"].ToolTipText = "Check this box to select this document.";
}
// Disable the functionality button if no rows.
if (this.uiDocumentDataGrid.RowCount == 0)
{
this.uiSendButton.Enabled = false;
}
}
No tooltip shows with this method. Am I missing something obvious?
Don’t try setting the ToolTip value of cells in the constructor of the form. Try setting them in the Load or Shown events instead: